ConsoleOutput client and model

1. Added model for console output
   and corresponding request
3. Added client method to get console output.
4. Added tests for model and client.

Change-Id: Ifad82323990965b333239c59105dec2668a95baa
This commit is contained in:
Sumanth Nagadavalli
2013-07-22 13:54:58 +05:30
parent 89703d7933
commit 663e817ffb
26 changed files with 714 additions and 32 deletions

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,58 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from cafe.engine.clients.rest import AutoMarshallingRestClient
from cloudcafe.compute.extensions.console_output_api.models.requests\
import GetConsoleOutput
from cloudcafe.compute.extensions.console_output_api.models.\
console_output import VncConsoleOutput
class ConsoleOutputClient(AutoMarshallingRestClient):
def __init__(self, url, auth_token, serialize_format=None,
deserialize_format=None):
super(ConsoleOutputClient, self).__init__(
serialize_format, deserialize_format)
self.auth_token = auth_token
self.default_headers['X-Auth-Token'] = auth_token
ct = ''.join(['application/', self.serialize_format])
accept = ''.join(['application/', self.deserialize_format])
self.default_headers['Content-Type'] = ct
self.default_headers['Accept'] = accept
self.url = url
def get_console_output(self, server_id, length,
requestslib_kwargs=None):
"""
@summary: Returns Console Output for a server
@param server_id: The id of an existing server
@type server_id: String
@param length: Number of lines of console output
@type length: String
@return: Console Output for the server
@rtype: Requests.response
"""
url = '{base_url}/servers/{server_id}/action'.format(
base_url=self.url, server_id=server_id)
get_console_output_request_object = GetConsoleOutput(length=length)
resp = self.request('POST', url,
request_entity=get_console_output_request_object,
response_entity_type=VncConsoleOutput,
requestslib_kwargs=requestslib_kwargs)
return resp

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,22 @@
import json
import xml.etree.ElementTree as ET
from cafe.engine.models.base import AutoMarshallingModel
from cloudcafe.compute.common.constants import Constants
class VncConsoleOutput(AutoMarshallingModel):
def __init__(self, output):
self.output = output
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = json.loads(serialized_str)
return VncConsoleOutput(output=json_dict.get("output"))
@classmethod
def _xml_to_obj(cls, serialized_str):
element = ET.fromstring(serialized_str)
cls._remove_xml_etree_namespace(element, Constants.XML_API_NAMESPACE)
return VncConsoleOutput(output=element.text)

View File

@@ -0,0 +1,41 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import json
import xml.etree.ElementTree as ET
from cafe.engine.models.base import AutoMarshallingModel
from cloudcafe.compute.common.constants import Constants
class GetConsoleOutput(AutoMarshallingModel):
"""
Get Console Output Request Object
"""
def __init__(self, length):
self.length = length
def _obj_to_json(self):
json_dict = {"length": str(self.length)}
return json.dumps({"os-getConsoleOutput": json_dict})
def _obj_to_xml(self):
xml = Constants.XML_HEADER
element = ET.Element("os-getConsoleOutput")
element.set("length", str(self.length))
xml += ET.tostring(element)
return xml

View File

@@ -15,8 +15,12 @@ limitations under the License.
"""
from cafe.engine.clients.rest import AutoMarshallingRestClient
from cloudcafe.compute.extensions.vnc_console_api.models.vnc_console import \
GetConsole, VncConsole
from cloudcafe.compute.extensions.vnc_console_api.models.requests\
import GetVncConsole
from cloudcafe.compute.extensions.vnc_console_api.models.vnc_console\
import VncConsole
class VncConsoleClient(AutoMarshallingRestClient):
@@ -33,9 +37,18 @@ class VncConsoleClient(AutoMarshallingRestClient):
self.default_headers['Accept'] = accept
self.url = url
def get_vnc_console(self, server_id, vnc_type, tenant_id=None,
def get_vnc_console(self, server_id, vnc_type,
requestslib_kwargs=None):
request = GetConsole(vnc_type=vnc_type, tenant_id=tenant_id)
"""
@summary: Returns Console for a server
@param server_id: The id of an existing server
@type server_id: String
@param vnc_type: Type of console, i.e, novnc, xvnc
@type vnc_type: String
@return: A console for the server
@rtype: Requests.response
"""
request = GetVncConsole(type=vnc_type)
url = '{base_url}/servers/{server_id}/action'.format(
base_url=self.url, server_id=server_id)

View File

@@ -0,0 +1,41 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import json
import xml.etree.ElementTree as ET
from cafe.engine.models.base import AutoMarshallingModel
from cloudcafe.compute.common.constants import Constants
class GetVncConsole(AutoMarshallingModel):
"""
Get Console Request Object
"""
def __init__(self, type):
self.type = type
def _obj_to_json(self):
json_dict = {"type": self.type}
return json.dumps({"os-getVNCConsole": json_dict})
def _obj_to_xml(self):
xml = Constants.XML_HEADER
element = ET.Element("os-getVNCConsole")
element.set("type", self.type)
xml += ET.tostring(element)
return xml

View File

@@ -1,39 +1,33 @@
import json
import xml.etree.ElementTree as ET
from cafe.engine.models.base import AutoMarshallingModel
class GetConsole(AutoMarshallingModel):
def __init__(self, vnc_type=None, tenant_id=None):
super(GetConsole, self).__init__()
self.vnc_type = vnc_type
self.tenant_id = tenant_id
def _obj_to_json(self):
ret = {'os-getVNCConsole': self._obj_to_dict()}
return json.dumps(ret)
def _obj_to_dict(self):
ret = {}
ret['type'] = self.vnc_type
ret['tenant_id'] = self.tenant_id
self._remove_empty_values(ret)
return ret
from cloudcafe.compute.common.constants import Constants
class VncConsole(AutoMarshallingModel):
def __init__(self, vnc_type=None, url=None):
super(VncConsole, self).__init__()
self.type = vnc_type
def __init__(self, type, url):
self.type = type
self.url = url
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = json.loads(serialized_str)
console_dict = json_dict.get('console')
console = VncConsole(vnc_type=console_dict.get('type'),
url=console_dict.get('url'))
return console
return cls._dict_to_obj(json_dict.get("console"))
@classmethod
def _dict_to_obj(cls, dict):
return VncConsole(type=dict.get("type"),
url=dict.get("url"))
@classmethod
def _xml_to_obj(cls, serialized_str):
element = ET.fromstring(serialized_str)
cls._remove_xml_etree_namespace(element, Constants.XML_API_NAMESPACE)
return cls._xml_ele_to_obj(element)
@classmethod
def _xml_ele_to_obj(cls, element):
return VncConsole(type=element.find("type").text,
url=element.find("url").text)

View File

@@ -18,7 +18,7 @@ from cafe.engine.clients.rest import AutoMarshallingRestClient
from cloudcafe.common.tools.datagen import rand_name
from cloudcafe.compute.common.models.metadata import Metadata
from cloudcafe.compute.common.models.metadata import MetadataItem
from cloudcafe.compute.extensions.security_groups_api.models.security_group\
from cloudcafe.compute.extensions.security_groups_api.models.security_group \
import SecurityGroups, SecurityGroup
from cloudcafe.compute.servers_api.models.servers import Server
from cloudcafe.compute.servers_api.models.servers import Addresses

View File

@@ -44,6 +44,13 @@ class ServersConfig(ConfigSectionInterface):
"""
return int(self.get("server_build_timeout"))
@property
def server_boot_timeout(self):
"""
Length of time to wait before timing out on a server boot
"""
return int(self.get("server_boot_timeout"))
@property
def server_resize_timeout(self):
"""

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,37 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
class ConsoleOutputMockResponse(object):
def __init__(self, format):
self.format = format
def get_console_output(self):
return getattr(self, '_{0}_console_output'.format(self.format))()
def _json_console_output(self):
return """
{
"output": "FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE"
}"""
def _xml_console_output(self):
return """
<?xml version='1.0' encoding='UTF-8'?>
<output>FAKE CONSOLE OUTPUT
ANOTHER LAST LINE
</output>"""

View File

@@ -0,0 +1,50 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from httpretty import HTTPretty
from cloudcafe.compute.extensions.console_output_api.client\
import ConsoleOutputClient
from metatests.cloudcafe.compute.extensions.console_output.\
client.responses import ConsoleOutputMockResponse
from metatests.cloudcafe.compute.fixtures import ClientTestFixture
class ConsoleOutputClientTest(ClientTestFixture):
@classmethod
def setUpClass(cls):
super(ConsoleOutputClientTest, cls).setUpClass()
cls.vnc_console_client = ConsoleOutputClient(
url=cls.COMPUTE_API_ENDPOINT,
auth_token=cls.AUTH_TOKEN,
serialize_format=cls.FORMAT,
deserialize_format=cls.FORMAT
)
cls.console_uri = "{0}/servers/{1}/action".format(
cls.COMPUTE_API_ENDPOINT, cls.SERVER_ID)
cls.mock_response = ConsoleOutputMockResponse(cls.FORMAT)
def test_get_console_output(self):
HTTPretty.register_uri(HTTPretty.POST, self.console_uri,
body=self.mock_response.get_console_output())
response = self.vnc_console_client.get_console_output(
server_id=self.SERVER_ID, length=50)
self.assertEqual(200, response.status_code)
self.assertEqual(self.mock_response.get_console_output(),
response.content)

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,48 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from cloudcafe.compute.extensions.console_output_api.models.console_output\
import VncConsoleOutput
class ConsoleOutputDomainTest():
def test_console_output_attributes(self):
self.assertEqual(self.console_output.output, "some output")
class ConsoleOutputDomainJSONTest(unittest.TestCase, ConsoleOutputDomainTest):
@classmethod
def setUpClass(cls):
cls.console_output_json = """
{"output": "some output"}
"""
cls.console_output = VncConsoleOutput.deserialize(
cls.console_output_json, "json")
class ConsoleOutputDomainXMLTest(unittest.TestCase, ConsoleOutputDomainTest):
@classmethod
def setUpClass(cls):
cls.console_output_xml = (
"""<?xml version='1.0' encoding='UTF-8'?>
<output>some output</output>""")
cls.console_output = VncConsoleOutput.deserialize(
cls.console_output_xml, "xml")

View File

@@ -0,0 +1,37 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from cloudcafe.compute.extensions.console_output_api.models.requests\
import GetConsoleOutput
class ConsoleOutputRequestsTest(unittest.TestCase):
def test_serialize_get_console_output_request_to_json(self):
request_obj = GetConsoleOutput(length=50)
json_serialized_request = request_obj.serialize("json")
expected_json = '{"os-getConsoleOutput": {"length": "50"}}'
self.assertEqual(json_serialized_request, expected_json)
def test_serialize_get_console_request_to_xml(self):
request_obj = GetConsoleOutput(length=50)
xml_serialized_request = request_obj.serialize("xml")
expected_xml = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
'<os-getConsoleOutput length="50" />')
self.assertEqual(xml_serialized_request,
expected_xml.replace("\n", " "))

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,58 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
class VncConsoleMockResponse():
def __init__(self, format):
self.format = format
def get_console(self):
return getattr(self, '_{0}_console'.format(self.format))()
def get_console_output(self):
return getattr(self, '_{0}_console_output'.format(self.format))()
def _json_console(self):
return """
{
"console":
{
"type": "novnc",
"url": "http://example.com/vnc_auto.html?token=1234"
}
}"""
def _xml_console(self):
return """
<?xml version='1.0' encoding='UTF-8'?>
<console>
<type>novnc</type>
<url>http://example.com/vnc_auto.html?token=1234</url>
</console>"""
def _json_console_output(self):
return """
{
"output": "FAKE CONSOLE OUTPUT\nANOTHER\nLAST LINE"
}"""
def _xml_console_output(self):
return """
<?xml version='1.0' encoding='UTF-8'?>
<output>FAKE CONSOLE OUTPUT
ANOTHER LAST LINE
</output>"""

View File

@@ -0,0 +1,47 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from httpretty import HTTPretty
from cloudcafe.compute.common.types import VncConsoleTypes
from cloudcafe.compute.extensions.vnc_console_api.client import VncConsoleClient
from metatests.cloudcafe.compute.extensions.vnc_console.client.responses\
import VncConsoleMockResponse
from metatests.cloudcafe.compute.fixtures import ClientTestFixture
class VncConsoleClientTest(ClientTestFixture):
@classmethod
def setUpClass(cls):
super(VncConsoleClientTest, cls).setUpClass()
cls.vnc_console_client = VncConsoleClient(
url=cls.COMPUTE_API_ENDPOINT,
auth_token=cls.AUTH_TOKEN,
serialize_format=cls.FORMAT,
deserialize_format=cls.FORMAT)
cls.console_uri = "{0}/servers/{1}/action".format(
cls.COMPUTE_API_ENDPOINT, cls.SERVER_ID)
cls.mock_response = VncConsoleMockResponse(cls.FORMAT)
def test_get_console(self):
HTTPretty.register_uri(HTTPretty.POST, self.console_uri,
body=self.mock_response.get_console())
response = self.vnc_console_client.get_vnc_console(
server_id=self.SERVER_ID, vnc_type=VncConsoleTypes.NOVNC)
self.assertEqual(200, response.status_code)
self.assertEqual(self.mock_response.get_console(), response.content)

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,57 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from cloudcafe.compute.extensions.vnc_console_api.models.vnc_console\
import VncConsole
class VncConsoleDomainTest():
def test_console_attributes(self):
self.assertEqual(self.console.type, "novnc")
self.assertEqual(self.console.url,
"http://example.com/vnc_auto.html?token=1234")
class VncConsoleDomainJSONTest(unittest.TestCase, VncConsoleDomainTest):
@classmethod
def setUpClass(cls):
cls.console_json = """
{
"console":
{
"type": "novnc",
"url": "http://example.com/vnc_auto.html?token=1234"
}
}"""
cls.console = VncConsole.deserialize(cls.console_json, "json")
class VncConsoleDomainXMLTest(unittest.TestCase, VncConsoleDomainTest):
@classmethod
def setUpClass(cls):
cls.console_xml = (
"""<?xml version='1.0' encoding='UTF-8'?>
<console>
<type>novnc</type>
<url>http://example.com/vnc_auto.html?token=1234</url>
</console>""")
cls.console = VncConsole.deserialize(cls.console_xml, "xml")

View File

@@ -0,0 +1,36 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest2 as unittest
from cloudcafe.compute.extensions.vnc_console_api.models.requests\
import GetVncConsole
class ConsoleRequestsTest(unittest.TestCase):
def test_serialize_get_console_request_to_json(self):
request_obj = GetVncConsole(type="novnc")
json_serialized_request = request_obj.serialize("json")
expected_json = '{"os-getVNCConsole": {"type": "novnc"}}'
self.assertEqual(json_serialized_request, expected_json)
def test_serialize_get_console_request_to_xml(self):
request_obj = GetVncConsole(type="novnc")
xml_serialized_request = request_obj.serialize("xml")
expected_xml = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
'<os-getVNCConsole type="novnc" />')
self.assertEqual(xml_serialized_request,
expected_xml.replace("\n", " "))

View File

@@ -24,6 +24,7 @@ class ClientTestFixture(unittest.TestCase):
COMPUTE_API_ENDPOINT = 'http://localhost:5000/v1'
HOST_NAME = '787f4f6dda1b409bb8b2f9082349690e'
TENANT_ID = 'c34dbd5940514344b54747487266a4b6'
SERVER_ID = '1234'
FORMAT = 'json'
CONTENT_TYPE = 'application/{0}'.format(FORMAT)
ACCEPT = 'application/{0}'.format(FORMAT)