Add a test case for creating a node with VLAN.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/9e24600b Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9e24600b Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9e24600b Branch: refs/heads/trunk Commit: 9e24600b898fb753e09695a5d7961accb7ce77f5 Parents: f086c44 Author: Tomaz Muraus <[email protected]> Authored: Fri Jan 31 19:26:24 2014 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Fri Jan 31 19:26:24 2014 +0100 ---------------------------------------------------------------------- .../servers_create_with_vlan.json | 68 ++++++++++++++++++++ libcloud/test/compute/test_cloudsigma_v2_0.py | 29 ++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/9e24600b/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create_with_vlan.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create_with_vlan.json b/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create_with_vlan.json new file mode 100644 index 0000000..ee1b2d7 --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudsigma_2_0/servers_create_with_vlan.json @@ -0,0 +1,68 @@ +{ + "objects": [ + { + "context": true, + "cpu": 1100, + "cpu_model": null, + "cpus_instead_of_cores": false, + "drives": [ + { + "boot_order": 1, + "dev_channel": "0:0", + "device": "ide", + "drive": { + "resource_uri": "/api/2.0/drives/7c0efbb2-b1e8-4e77-9d72-9f9f9d75ae7b/", + "uuid": "7c0efbb2-b1e8-4e77-9d72-9f9f9d75ae7b" + }, + "runtime": null + } + ], + "enable_numa": false, + "hv_relaxed": false, + "hv_tsc": false, + "mem": 671088640, + "meta": {}, + "name": "test node vlan", + "nics": [ + { + "boot_order": null, + "firewall_policy": null, + "ip_v4_conf": { + "conf": "dhcp", + "ip": null + }, + "ip_v6_conf": null, + "mac": "22:94:75:3c:16:34", + "model": "virtio", + "runtime": null, + "vlan": null + }, + { + "boot_order": null, + "firewall_policy": null, + "ip_v4_conf": null, + "ip_v6_conf": null, + "mac": "22:84:c4:af:f3:fc", + "model": "virtio", + "runtime": null, + "vlan": { + "resource_uri": "/api/2.0/vlans/39ae851d-433f-4ac2-a803-ffa24cb1fa3e/", + "uuid": "39ae851d-433f-4ac2-a803-ffa24cb1fa3e" + } + } + ], + "owner": { + "resource_uri": "/api/2.0/user/69fcfc03-d635-4f99-a8b3-e1b73637cb5d/", + "uuid": "69fcfc03-d635-4f99-a8b3-e1b73637cb5d" + }, + "requirements": [], + "resource_uri": "/api/2.0/servers/c8b034fb-9e66-4892-be12-a36121d4b704/", + "runtime": null, + "smp": 1, + "status": "stopped", + "tags": [], + "uuid": "9de75ed6_fd33_45e2_963f_d405f31fd911", + "vnc_password": "testserver" + } + ] +} http://git-wip-us.apache.org/repos/asf/libcloud/blob/9e24600b/libcloud/test/compute/test_cloudsigma_v2_0.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_cloudsigma_v2_0.py b/libcloud/test/compute/test_cloudsigma_v2_0.py index 358c1e7..349858e 100644 --- a/libcloud/test/compute/test_cloudsigma_v2_0.py +++ b/libcloud/test/compute/test_cloudsigma_v2_0.py @@ -14,6 +14,12 @@ # limitations under the License. import sys + +try: + import simplejson as json +except: + import json + from libcloud.utils.py3 import httplib from libcloud.common.types import InvalidCredsError @@ -94,6 +100,19 @@ class CloudSigmaAPI20BaseTestCase(object): self.assertEqual(len(node.extra['nics']), 1) self.assertEqual(node.extra['nics'][0]['ip_v4_conf']['conf'], 'dhcp') + def test_create_node_with_vlan(self): + image = self.driver.list_images()[0] + size = self.driver.list_sizes()[0] + + vlan_uuid = '39ae851d-433f-4ac2-a803-ffa24cb1fa3e' + + node = self.driver.create_node(name='test node vlan', size=size, + image=image, ex_vlan=vlan_uuid) + self.assertEqual(node.name, 'test node vlan') + self.assertEqual(len(node.extra['nics']), 2) + self.assertEqual(node.extra['nics'][0]['ip_v4_conf']['conf'], 'dhcp') + self.assertEqual(node.extra['nics'][1]['vlan']['uuid'], vlan_uuid) + def test_destroy_node(self): status = self.driver.destroy_node(node=self.node) self.assertTrue(status) @@ -436,7 +455,15 @@ class CloudSigmaMockHttp(MockHttpTestCase): def _api_2_0_servers(self, method, url, body, headers): if method == 'POST': # create_node - body = self.fixtures.load('servers_create.json') + + parsed = json.loads(body) + + if 'vlan' in parsed['name']: + self.assertEqual(len(parsed['nics']), 2) + body = self.fixtures.load('servers_create_with_vlan.json') + else: + body = self.fixtures.load('servers_create.json') + return (httplib.CREATED, body, {}, httplib.responses[httplib.CREATED]) def _api_2_0_servers_9de75ed6_fd33_45e2_963f_d405f31fd911_action_start(self, method, url, body, headers):
