diff --git a/cloudcafe/compute/extensions/rescue_api/models/requests.py b/cloudcafe/compute/extensions/rescue_api/models/requests.py index 6cf461ab..dcd75324 100644 --- a/cloudcafe/compute/extensions/rescue_api/models/requests.py +++ b/cloudcafe/compute/extensions/rescue_api/models/requests.py @@ -22,30 +22,26 @@ from cloudcafe.compute.common.constants import Constants class RescueMode(AutoMarshallingModel): - ROOT_TAG = 'rescue' def _obj_to_json(self): - ret = self._auto_to_dict() - return json.dumps(ret) + return json.dumps({'rescue': {}}) def _obj_to_xml(self): xml = Constants.XML_HEADER - element = ET.Element(self.ROOT_TAG) + element = ET.Element('rescue') element.set('xmlns', Constants.XML_API_RESCUE) xml += ET.tostring(element) return xml class ExitRescueMode(AutoMarshallingModel): - ROOT_TAG = 'unrescue' def _obj_to_json(self): - ret = self._auto_to_dict() - return json.dumps(ret) + return json.dumps({'unrescue': {}}) def _obj_to_xml(self): xml = Constants.XML_HEADER - element = ET.Element(self.ROOT_TAG) + element = ET.Element('unrescue') element.set('xmlns', Constants.XML_API_UNRESCUE) xml += ET.tostring(element) return xml diff --git a/cloudcafe/compute/extensions/rescue_api/models/responses.py b/cloudcafe/compute/extensions/rescue_api/models/responses.py index 730d9515..f64f517e 100644 --- a/cloudcafe/compute/extensions/rescue_api/models/responses.py +++ b/cloudcafe/compute/extensions/rescue_api/models/responses.py @@ -15,13 +15,16 @@ 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 RescueResponse(AutoMarshallingModel): def __init__(self, admin_pass): + super(RescueResponse, self).__init__() self.admin_pass = admin_pass def __repr__(self): @@ -33,16 +36,12 @@ class RescueResponse(AutoMarshallingModel): @classmethod def _json_to_obj(cls, serialized_str): json_dict = json.loads(serialized_str) - return cls._dict_to_obj(json_dict) - - @classmethod - def _dict_to_obj(cls, json_dict): return RescueResponse(json_dict.get('adminPass')) @classmethod def _xml_to_obj(cls, serialized_str): - raise NotImplemented - - @classmethod - def _xml_ele_to_obj(cls, xml_ele): - raise NotImplemented + element = ET.fromstring(serialized_str) + cls._remove_xml_etree_namespace(element, Constants.XML_API_NAMESPACE) + cls._remove_xml_etree_namespace(element, + Constants.XML_API_ATOM_NAMESPACE) + return RescueResponse(element.text) diff --git a/metatests/cloudcafe/compute/extensions/rescue/__init__.py b/metatests/cloudcafe/compute/extensions/rescue/__init__.py new file mode 100644 index 00000000..59ab77fa --- /dev/null +++ b/metatests/cloudcafe/compute/extensions/rescue/__init__.py @@ -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. +""" diff --git a/metatests/cloudcafe/compute/extensions/rescue/models/__init__.py b/metatests/cloudcafe/compute/extensions/rescue/models/__init__.py new file mode 100644 index 00000000..59ab77fa --- /dev/null +++ b/metatests/cloudcafe/compute/extensions/rescue/models/__init__.py @@ -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. +""" diff --git a/metatests/cloudcafe/compute/extensions/rescue/models/test_rescue.py b/metatests/cloudcafe/compute/extensions/rescue/models/test_rescue.py new file mode 100644 index 00000000..bf41c96f --- /dev/null +++ b/metatests/cloudcafe/compute/extensions/rescue/models/test_rescue.py @@ -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 unittest2 as unittest + +from cloudcafe.compute.extensions.rescue_api.models.responses \ + import RescueResponse + + +class RescueResponseModelTest(object): + + def test_admin_password(self): + self.assertEqual(self.rescue.admin_pass, 'MySecretPass') + +class RescueResponseXMLModelTest(unittest.TestCase, RescueResponseModelTest): + + @classmethod + def setUpClass(cls): + cls.rescue_xml = 'MySecretPass' + cls.rescue = RescueResponse.deserialize(cls.rescue_xml, 'xml') + + +class RescueResponseJSONModelTest(unittest.TestCase, RescueResponseModelTest): + + @classmethod + def setUpClass(cls): + cls.rescue_json = '{"adminPass": "MySecretPass"}' + cls.rescue = RescueResponse.deserialize(cls.rescue_json, 'json') \ No newline at end of file