Adds Ironic request models
* Adds request models for chasis, nodes, and ports * Adds unit tests for request models Change-Id: I34d49a003a6cbc6e4f3622f036318a51769451a4
This commit is contained in:
parent
7968b2fe66
commit
5f870f9058
@ -13,3 +13,25 @@ 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
|
||||
|
||||
from cafe.engine.models.base import AutoMarshallingModel
|
||||
|
||||
|
||||
class CreateChassis(AutoMarshallingModel):
|
||||
|
||||
def __init__(self, description=None, extra=None):
|
||||
super(CreateChassis, self).__init__()
|
||||
extra = extra or {}
|
||||
|
||||
self.description = description
|
||||
self.extra = extra
|
||||
|
||||
def _obj_to_json(self):
|
||||
create_request = {
|
||||
'description': self.description,
|
||||
'extra': self.extra
|
||||
}
|
||||
self._remove_empty_values(create_request)
|
||||
return json.dumps(create_request)
|
||||
|
@ -13,3 +13,36 @@ 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
|
||||
|
||||
from cafe.engine.models.base import AutoMarshallingModel
|
||||
|
||||
|
||||
class CreateNode(AutoMarshallingModel):
|
||||
|
||||
def __init__(
|
||||
self, chassis_uuid=None, driver=None, properties=None,
|
||||
driver_info=None, extra=None):
|
||||
super(CreateNode, self).__init__()
|
||||
|
||||
properties = properties or {}
|
||||
driver_info = driver_info or {}
|
||||
extra = extra or {}
|
||||
|
||||
self.chassis_uuid = chassis_uuid
|
||||
self.driver = driver
|
||||
self.properties = properties
|
||||
self.driver_info = driver_info
|
||||
self.extra = extra
|
||||
|
||||
def _obj_to_json(self):
|
||||
create_request = {
|
||||
'chassis_uuid': self.chassis_uuid,
|
||||
'driver': self.driver,
|
||||
'properties': self.properties,
|
||||
'driver_info': self.driver_info,
|
||||
'extra': self.extra
|
||||
}
|
||||
self._remove_empty_values(create_request)
|
||||
return json.dumps(create_request)
|
||||
|
@ -13,3 +13,28 @@ 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
|
||||
|
||||
from cafe.engine.models.base import AutoMarshallingModel
|
||||
|
||||
|
||||
class CreatePort(AutoMarshallingModel):
|
||||
|
||||
def __init__(
|
||||
self, node_uuid=None, address=None, extra=None):
|
||||
super(CreatePort, self).__init__()
|
||||
extra = extra or {}
|
||||
|
||||
self.node_uuid = node_uuid
|
||||
self.address = address
|
||||
self.extra = extra
|
||||
|
||||
def _obj_to_json(self):
|
||||
create_request = {
|
||||
'node_uuid': self.node_uuid,
|
||||
'address': self.address,
|
||||
'extra': self.extra
|
||||
}
|
||||
self._remove_empty_values(create_request)
|
||||
return json.dumps(create_request)
|
||||
|
@ -0,0 +1,34 @@
|
||||
"""
|
||||
Copyright 2014 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 unittest
|
||||
|
||||
from cloudcafe.bare_metal.chassis.models.requests import CreateChassis
|
||||
|
||||
|
||||
class CreateChassisModelTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
chassis_request = CreateChassis(
|
||||
description='test_chassis', extra={'meta1': 'value1'})
|
||||
cls.chassis_json = chassis_request.serialize('json')
|
||||
|
||||
def test_create_chassis_json(self):
|
||||
expected_json = (
|
||||
'{"description": "test_chassis", "extra": {"meta1": "value1"}}')
|
||||
self.assertEqual(self.chassis_json, expected_json)
|
@ -0,0 +1,37 @@
|
||||
"""
|
||||
Copyright 2014 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 unittest
|
||||
|
||||
from cloudcafe.bare_metal.nodes.models.requests import CreateNode
|
||||
|
||||
|
||||
class CreateNodeModelTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
node_request = CreateNode(
|
||||
chassis_uuid='1', driver='fake', properties={'key1': 'val1'},
|
||||
driver_info={'key3': 'val3'}, extra={'key2': 'val2'})
|
||||
cls.node_json = node_request.serialize('json')
|
||||
|
||||
def test_create_node_json(self):
|
||||
expected_json = (
|
||||
'{"driver_info": {"key3": "val3"}, "driver": "fake", '
|
||||
'"properties": {"key1": "val1"}, "chassis_uuid": "1", '
|
||||
'"extra": {"key2": "val2"}}')
|
||||
self.assertEqual(self.node_json, expected_json)
|
@ -0,0 +1,36 @@
|
||||
"""
|
||||
Copyright 2014 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 unittest
|
||||
|
||||
from cloudcafe.bare_metal.ports.models.requests import CreatePort
|
||||
|
||||
|
||||
class CreatePortModelTest(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
port_request = CreatePort(
|
||||
node_uuid="1", address="52:54:00:e5:57:d4",
|
||||
extra={'meta1': 'value1'})
|
||||
cls.port_json = port_request.serialize('json')
|
||||
|
||||
def test_create_chassis_json(self):
|
||||
expected_json = (
|
||||
'{"extra": {"meta1": "value1"}, "node_uuid": "1", '
|
||||
'"address": "52:54:00:e5:57:d4"}')
|
||||
self.assertEqual(self.port_json, expected_json)
|
Loading…
x
Reference in New Issue
Block a user