Merge "Refactored rescue models up to meeting coding standards"
This commit is contained in:
commit
9498801575
@ -22,30 +22,26 @@ from cloudcafe.compute.common.constants import Constants
|
|||||||
|
|
||||||
|
|
||||||
class RescueMode(AutoMarshallingModel):
|
class RescueMode(AutoMarshallingModel):
|
||||||
ROOT_TAG = 'rescue'
|
|
||||||
|
|
||||||
def _obj_to_json(self):
|
def _obj_to_json(self):
|
||||||
ret = self._auto_to_dict()
|
return json.dumps({'rescue': {}})
|
||||||
return json.dumps(ret)
|
|
||||||
|
|
||||||
def _obj_to_xml(self):
|
def _obj_to_xml(self):
|
||||||
xml = Constants.XML_HEADER
|
xml = Constants.XML_HEADER
|
||||||
element = ET.Element(self.ROOT_TAG)
|
element = ET.Element('rescue')
|
||||||
element.set('xmlns', Constants.XML_API_RESCUE)
|
element.set('xmlns', Constants.XML_API_RESCUE)
|
||||||
xml += ET.tostring(element)
|
xml += ET.tostring(element)
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
|
||||||
class ExitRescueMode(AutoMarshallingModel):
|
class ExitRescueMode(AutoMarshallingModel):
|
||||||
ROOT_TAG = 'unrescue'
|
|
||||||
|
|
||||||
def _obj_to_json(self):
|
def _obj_to_json(self):
|
||||||
ret = self._auto_to_dict()
|
return json.dumps({'unrescue': {}})
|
||||||
return json.dumps(ret)
|
|
||||||
|
|
||||||
def _obj_to_xml(self):
|
def _obj_to_xml(self):
|
||||||
xml = Constants.XML_HEADER
|
xml = Constants.XML_HEADER
|
||||||
element = ET.Element(self.ROOT_TAG)
|
element = ET.Element('unrescue')
|
||||||
element.set('xmlns', Constants.XML_API_UNRESCUE)
|
element.set('xmlns', Constants.XML_API_UNRESCUE)
|
||||||
xml += ET.tostring(element)
|
xml += ET.tostring(element)
|
||||||
return xml
|
return xml
|
||||||
|
@ -15,13 +15,16 @@ limitations under the License.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from cafe.engine.models.base import AutoMarshallingModel
|
from cafe.engine.models.base import AutoMarshallingModel
|
||||||
|
from cloudcafe.compute.common.constants import Constants
|
||||||
|
|
||||||
|
|
||||||
class RescueResponse(AutoMarshallingModel):
|
class RescueResponse(AutoMarshallingModel):
|
||||||
|
|
||||||
def __init__(self, admin_pass):
|
def __init__(self, admin_pass):
|
||||||
|
super(RescueResponse, self).__init__()
|
||||||
self.admin_pass = admin_pass
|
self.admin_pass = admin_pass
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -33,16 +36,12 @@ class RescueResponse(AutoMarshallingModel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _json_to_obj(cls, serialized_str):
|
def _json_to_obj(cls, serialized_str):
|
||||||
json_dict = json.loads(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'))
|
return RescueResponse(json_dict.get('adminPass'))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _xml_to_obj(cls, serialized_str):
|
def _xml_to_obj(cls, serialized_str):
|
||||||
raise NotImplemented
|
element = ET.fromstring(serialized_str)
|
||||||
|
cls._remove_xml_etree_namespace(element, Constants.XML_API_NAMESPACE)
|
||||||
@classmethod
|
cls._remove_xml_etree_namespace(element,
|
||||||
def _xml_ele_to_obj(cls, xml_ele):
|
Constants.XML_API_ATOM_NAMESPACE)
|
||||||
raise NotImplemented
|
return RescueResponse(element.text)
|
||||||
|
15
metatests/cloudcafe/compute/extensions/rescue/__init__.py
Normal file
15
metatests/cloudcafe/compute/extensions/rescue/__init__.py
Normal 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.
|
||||||
|
"""
|
@ -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.
|
||||||
|
"""
|
@ -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 = '<adminPass>MySecretPass</adminPass>'
|
||||||
|
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')
|
Loading…
x
Reference in New Issue
Block a user