From 9d31912f36e24ed29b909c25e0b1afcdc7983ed8 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Tue, 22 Dec 2015 18:10:59 +0300 Subject: [PATCH] update config & fix test against google Change-Id: I713724a866a9fc8727bf0ad150c596bc4b4b6d12 --- gceapi/tests/functional/api/test_addresses.py | 2 +- gceapi/tests/functional/api/test_disks.py | 19 +++++++-------- gceapi/tests/functional/api/test_firewalls.py | 2 +- gceapi/tests/functional/api/test_networks.py | 2 +- gceapi/tests/functional/api/test_routes.py | 2 +- gceapi/tests/functional/config_opts.py | 23 ++++++++++--------- gceapi/tests/functional/test_base.py | 9 ++++---- 7 files changed, 29 insertions(+), 30 deletions(-) diff --git a/gceapi/tests/functional/api/test_addresses.py b/gceapi/tests/functional/api/test_addresses.py index 3ea3b95..174f182 100644 --- a/gceapi/tests/functional/api/test_addresses.py +++ b/gceapi/tests/functional/api/test_addresses.py @@ -36,7 +36,7 @@ class TestAddressesBase(test_base.GCETestCase): cfg = self.cfg project_id = cfg.project_id region = cfg.region - self.trace('Crete address with options {}'.format(options)) + self.trace('Create address with options {}'.format(options)) request = self.addresses.insert( project=project_id, region=region, diff --git a/gceapi/tests/functional/api/test_disks.py b/gceapi/tests/functional/api/test_disks.py index 0b537be..3267a63 100644 --- a/gceapi/tests/functional/api/test_disks.py +++ b/gceapi/tests/functional/api/test_disks.py @@ -180,7 +180,7 @@ class TestDiskBase(TestImagesBase): cfg = self.cfg project_id = cfg.project_id zone = cfg.zone - self.trace('Crete disk with options {} source_image={}'. + self.trace('Create disk with options {} source_image={}'. format(options, source_image)) request = self.disks.insert( project=project_id, @@ -269,8 +269,9 @@ class TestDiskBase(TestImagesBase): self._create_disk(options, source_image=image['selfLink']) options['sourceImage'] = image['selfLink'] options['sourceImageId'] = image['id'] - # TODO(alexey-mr): image diskSizeGb is not supported by OS GCE - # options['sizeGb'] = image['diskSizeGb'] + if self.full_compatibility: + # TODO(alexey-mr): image diskSizeGb is not supported by OS GCE + options['sizeGb'] = image['diskSizeGb'] return self._ensure_disk_created(options) def _create_snapshot(self, disk_name, options): @@ -331,16 +332,12 @@ class TestDisks(TestDiskBase): self._delete_disk(name) def test_create_disk_from_image(self): - name = self._rand_name('testdisk') - image = 'projects/{}'.format(self.cfg.image) - options = { - 'name': name, - } - self._create_disk(options, source_image=image) + image_name, image_project = self._parse_image_url(self.cfg.image) + image = self._get_image(image_name, image_project) + disk = self._create_disk_from_image(image) # TODO(alexey-mr): image diskSizeGb is not supported by OS GCE # options['sizeGb'] = self._get_image_size(self.cfg.image) - self._ensure_disk_created(options, source_image=image) - self._delete_disk(name) + self._delete_disk(disk['name']) def test_create_disk_from_snapshot(self): data = self._create_disk_and_snapshot() diff --git a/gceapi/tests/functional/api/test_firewalls.py b/gceapi/tests/functional/api/test_firewalls.py index 7abb5f7..ac11912 100644 --- a/gceapi/tests/functional/api/test_firewalls.py +++ b/gceapi/tests/functional/api/test_firewalls.py @@ -30,7 +30,7 @@ class TestFirewallBase(test_networks.TestNetworksBase): def _create_firewall(self, options): project_id = self.cfg.project_id - self.trace('Crete firewall with options {}'.format(options)) + self.trace('Create firewall with options {}'.format(options)) request = self.firewalls.insert( project=project_id, body=options) diff --git a/gceapi/tests/functional/api/test_networks.py b/gceapi/tests/functional/api/test_networks.py index e8e8955..c7744a1 100644 --- a/gceapi/tests/functional/api/test_networks.py +++ b/gceapi/tests/functional/api/test_networks.py @@ -41,7 +41,7 @@ class TestNetworksBase(test_base.GCETestCase): def _create_network(self, options): project_id = self.cfg.project_id - self.trace('Crete network with options {}'.format(options)) + self.trace('Create network with options {}'.format(options)) request = self.networks.insert( project=project_id, body=options) diff --git a/gceapi/tests/functional/api/test_routes.py b/gceapi/tests/functional/api/test_routes.py index 5c25dd3..0a76f3c 100644 --- a/gceapi/tests/functional/api/test_routes.py +++ b/gceapi/tests/functional/api/test_routes.py @@ -39,7 +39,7 @@ class TestRouteBase(test_base.GCETestCase): def _create_route(self, options): project_id = self.cfg.project_id - self.trace('Crete route with options {}'.format(options)) + self.trace('Create route with options {}'.format(options)) request = self.routes.insert( project=project_id, body=options) diff --git a/gceapi/tests/functional/config_opts.py b/gceapi/tests/functional/config_opts.py index ddc0711..15f9b48 100644 --- a/gceapi/tests/functional/config_opts.py +++ b/gceapi/tests/functional/config_opts.py @@ -22,10 +22,10 @@ OPTIONS = [ # Generic options cfg.IntOpt('build_timeout', default=180, - help='Timeout'), + help='Timeout for build resources'), cfg.IntOpt('build_interval', default=1, - help='Interval'), + help='Interval between acquiring resource in wait func'), # GCE auth options cfg.StrOpt('cred_type', @@ -35,14 +35,14 @@ OPTIONS = [ '\n\tgcloud_auth - use app credentials that should be' 'obtained before via gcloud auth'), cfg.StrOpt('username', - default='demo', - help='User name'), + default=None, + help='User name for OpenStack identity'), cfg.StrOpt('password', - default='password', - help='User password'), + default=None, + help='User password for user in OpenStack'), cfg.StrOpt('auth_url', default='http://localhost:5000/v2.0/', - help='OAuth API relative URL'), + help='Auth API relative URL in case of OpenStack identity'), # GCE API schema cfg.StrOpt('schema', @@ -71,13 +71,13 @@ OPTIONS = [ # Name and ID, where Name is corresponds to Project ID in Google, ID is # Openstack ID's and has no relation to Google's ID and Number. cfg.StrOpt('project_id', - default='test', + default=None, help='GCE Project ID for testing'), cfg.StrOpt('zone', default='nova', help='GCE Zone for testing'), cfg.StrOpt('region', - default='us-central1', + default='regionone', help='GCE Region for testing'), cfg.StrOpt('networking', default='neutron', @@ -87,6 +87,7 @@ OPTIONS = [ default='n1-standard-1', help='Machine type - a type of instance ot be created'), cfg.StrOpt('image', - default='debian-cloud/global/images/debian-7-wheezy-v20150929', - help='Image to create instances'), + default=None, + help='Image to create instances. For example:' + 'debian-cloud/global/images/debian-7-wheezy-v20150929'), ] diff --git a/gceapi/tests/functional/test_base.py b/gceapi/tests/functional/test_base.py index 5417a76..5b8248a 100644 --- a/gceapi/tests/functional/test_base.py +++ b/gceapi/tests/functional/test_base.py @@ -44,9 +44,9 @@ def trace(msg): def safe_call(method): - def wrapper(self, *args, **kwargs): + def wrapper(*args, **kwargs): try: - return method(self, *args, **kwargs) + return method(*args, **kwargs) except Exception as err: trace('Exception {}'.format(err)) bt = traceback.format_exc() @@ -158,7 +158,7 @@ class GCEApi(object): @property def _host_url(self): cfg = CONF.gce - if self._is_standard_port(cfg.protocol, cfg.port): + if not cfg.port or self._is_standard_port(cfg.protocol, cfg.port): return '{}://{}'.format(cfg.protocol, cfg.host) return '{}://{}:{}'.format(cfg.protocol, cfg.host, cfg.port) @@ -356,7 +356,8 @@ class GCETestCase(base.BaseTestCase): @safe_call def _remove_cleanup(self, method, *args, **kwargs): v = (method, args, kwargs) - self._cleanups.remove(v) + if v in self._cleanups: + self._cleanups.remove(v) def _execute_async_request(self, request, project, zone=None, region=None): self.trace_request(request)