Repository: libcloud Updated Branches: refs/heads/trunk 206a5b49b -> f4dde7bbd
Fixed a bug in elasticstack node creation method where it would raise exceptions because of missing data in a response, and also fixed pulling the IP from the proper data item Fixed a class leak variable when creating multiple connections to different EC2 regions Closes #325 Signed-off-by: Tomaz Muraus <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f4dde7bb Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f4dde7bb Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f4dde7bb Branch: refs/heads/trunk Commit: f4dde7bbd37b2b51541bffed805b5c38bd353877 Parents: 206a5b4 Author: Michael Bennett <[email protected]> Authored: Tue Jun 24 15:44:56 2014 -0400 Committer: Tomaz Muraus <[email protected]> Committed: Thu Oct 23 23:01:17 2014 +0800 ---------------------------------------------------------------------- CHANGES.rst | 11 +++++ libcloud/compute/drivers/ec2.py | 2 +- libcloud/compute/drivers/elasticstack.py | 19 +++++--- .../elastichosts/offline_servers_info.json | 16 +++++++ .../fixtures/elastichosts/servers_info.json | 47 ++++++++++---------- libcloud/test/compute/test_ec2.py | 10 ++++- libcloud/test/compute/test_elasticstack.py | 18 ++++++++ 7 files changed, 91 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index b70ce36..da45e6c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -160,6 +160,17 @@ Compute (LIBCLOUD-625, LIBCLOUD-276, GITHUB-276) [Eric Johnson] +- Fix a bug in Elasticstack node creation method where it would raise + exceptions because of missing data in a response, and also fix pulling the + IP from the proper data item. + (GITHUB-325) + [Michael Bennett] + +- Fix a bug which prevented user to connect and instantiate multiple EC2 driver + instances for different regions at the same time. + (GITHUB-325) + [Michael Bennett] + Storage ~~~~~~~ http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 6d98c9a..217ed4c 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -5386,7 +5386,7 @@ class EC2NodeDriver(BaseEC2NodeDriver): self.api_name = details['api_name'] self.country = details['country'] - self.connectionCls.host = details['endpoint'] + host = host or details['endpoint'] super(EC2NodeDriver, self).__init__(key=key, secret=secret, secure=secure, host=host, http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/libcloud/compute/drivers/elasticstack.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/elasticstack.py b/libcloud/compute/drivers/elasticstack.py index da3863a..739fa8f 100644 --- a/libcloud/compute/drivers/elasticstack.py +++ b/libcloud/compute/drivers/elasticstack.py @@ -453,15 +453,22 @@ class ElasticStackBaseNodeDriver(NodeDriver): except KeyError: state = NodeState.UNKNOWN - if isinstance(data['nic:0:dhcp'], list): - public_ip = data['nic:0:dhcp'] + if 'nic:0:dhcp:ip' in data: + if isinstance(data['nic:0:dhcp:ip'], list): + public_ip = data['nic:0:dhcp:ip'] + else: + public_ip = [data['nic:0:dhcp:ip']] else: - public_ip = [data['nic:0:dhcp']] + public_ip = [] extra = {'cpu': data['cpu'], - 'smp': data['smp'], - 'mem': data['mem'], - 'started': data['started']} + 'mem': data['mem']} + + if 'started' in data: + extra['started'] = data['started'] + + if 'smp' in data: + extra['smp'] = data['smp'] if 'vnc:ip' in data: extra['vnc:ip'] = data['vnc:ip'] http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/libcloud/test/compute/fixtures/elastichosts/offline_servers_info.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/elastichosts/offline_servers_info.json b/libcloud/test/compute/fixtures/elastichosts/offline_servers_info.json new file mode 100644 index 0000000..60b0433 --- /dev/null +++ b/libcloud/test/compute/fixtures/elastichosts/offline_servers_info.json @@ -0,0 +1,16 @@ +[ + { + "boot": "ide:0:0", + "cpu": 2000, + "ide:0:0": "b6049e7a-aa1b-47f9-b21d-cdf2354e28d3", + "mem": 1024, + "name": "test api node", + "nic:0:block": "tcp/21 tcp/22 tcp/23 tcp/25", + "nic:0:dhcp": "auto", + "nic:0:model": "virtio", + "server": "b605ca90-c3e6-4cee-85f8-a8ebdf8f9903", + "status": "stopped", + "user": "2164ce57-591a-43ee-ade5-e2fe0ee13c3f", + "vnc:password": "testvncpass" + } +] http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/libcloud/test/compute/fixtures/elastichosts/servers_info.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/elastichosts/servers_info.json b/libcloud/test/compute/fixtures/elastichosts/servers_info.json index 72b6b48..bb3fc35 100644 --- a/libcloud/test/compute/fixtures/elastichosts/servers_info.json +++ b/libcloud/test/compute/fixtures/elastichosts/servers_info.json @@ -1,27 +1,28 @@ [ { - "boot": "ide:0:0", - "cpu": 2000, - "ide:0:0": "b6049e7a-aa1b-47f9-b21d-cdf2354e28d3", - "ide:0:0:read:bytes": "299696128", - "ide:0:0:read:requests": "73168", - "ide:0:0:write:bytes": "321044480", - "ide:0:0:write:requests": "78380", - "mem": 1024, - "name": "test api node", - "nic:0:block": "tcp/21 tcp/22 tcp/23 tcp/25", - "nic:0:dhcp": ["1.2.3.4", "1.2.3.5"], - "nic:0:model": "virtio", - "rx": 679560, - "rx:packets": 644, - "server": "b605ca90-c3e6-4cee-85f8-a8ebdf8f9903", - "smp": 1, - "started": 1280723696, - "status": "active", - "tx": 21271, - "tx:packets": "251", - "user": "2164ce57-591a-43ee-ade5-e2fe0ee13c3f", - "vnc:ip": "216.151.208.174", + "boot": "ide:0:0", + "cpu": 2000, + "ide:0:0": "b6049e7a-aa1b-47f9-b21d-cdf2354e28d3", + "ide:0:0:read:bytes": "299696128", + "ide:0:0:read:requests": "73168", + "ide:0:0:write:bytes": "321044480", + "ide:0:0:write:requests": "78380", + "mem": 1024, + "name": "test api node", + "nic:0:block": "tcp/21 tcp/22 tcp/23 tcp/25", + "nic:0:dhcp": "auto", + "nic:0:dhcp:ip": ["1.2.3.4", "1.2.3.5"], + "nic:0:model": "virtio", + "rx": 679560, + "rx:packets": 644, + "server": "b605ca90-c3e6-4cee-85f8-a8ebdf8f9903", + "smp": 1, + "started": 1280723696, + "status": "active", + "tx": 21271, + "tx:packets": "251", + "user": "2164ce57-591a-43ee-ade5-e2fe0ee13c3f", + "vnc:ip": "216.151.208.174", "vnc:password": "testvncpass" } -] \ No newline at end of file +] http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/libcloud/test/compute/test_ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index 02ab8a8..4a2a2e6 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -56,8 +56,14 @@ class BaseEC2Tests(LibcloudTestCase): regions = REGION_DETAILS.keys() regions = [d for d in regions if d != 'nimbus'] - for region in regions: - EC2NodeDriver(*EC2_PARAMS, **{'region': region}) + region_endpoints = [ + EC2NodeDriver(*EC2_PARAMS, **{'region': region}).connection.host for region in regions + ] + + # Verify that each driver doesn't get the same API host endpoint + self.assertEqual(len(region_endpoints), + len(set(region_endpoints)), + "Multiple Region Drivers were given the same API endpoint") def test_instantiate_driver_invalid_regions(self): for region in ['invalid', 'nimbus']: http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4dde7bb/libcloud/test/compute/test_elasticstack.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_elasticstack.py b/libcloud/test/compute/test_elasticstack.py index 31896c8..40dea2e 100644 --- a/libcloud/test/compute/test_elasticstack.py +++ b/libcloud/test/compute/test_elasticstack.py @@ -106,6 +106,20 @@ class ElasticStackTestCase(object): self.assertEqual( node.extra['ide:0:0'], "b6049e7a-aa1b-47f9-b21d-cdf2354e28d3") + def test_list_offline_node(self): + self.mockHttp.type = 'OFFLINE' + + nodes = self.driver.list_nodes() + self.assertTrue(isinstance(nodes, list)) + self.assertEqual(len(nodes), 1) + + node = nodes[0] + self.assertEqual(len(node.public_ips), 0, "Public IPs was not empty") + self.assertNotIn('smp', node.extra) + self.assertNotIn('started', node.extra) + self.assertEqual( + node.extra['ide:0:0'], "b6049e7a-aa1b-47f9-b21d-cdf2354e28d3") + def test_list_sizes(self): images = self.driver.list_sizes() self.assertEqual(len(images), 6) @@ -256,6 +270,10 @@ class ElasticStackMockHttp(MockHttp): body = self.fixtures.load('servers_info.json') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _servers_info_OFFLINE(self, method, url, body, headers): + body = self.fixtures.load('offline_servers_info.json') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _servers_72258_set(self, method, url, body, headers): body = '{}' return (httplib.OK, body, {}, httplib.responses[httplib.OK])
