Просмотр исходного кода

Merge pull request #287 from CloudVE/fix_aws_provider_tests

Fixes for aws tests
Nuwan Goonasekera 4 лет назад
Родитель
Сommit
18615f4aca
3 измененных файлов с 24 добавлено и 17 удалено
  1. 4 0
      README.rst
  2. 2 2
      cloudbridge/providers/aws/resources.py
  3. 18 15
      cloudbridge/providers/aws/services.py

+ 4 - 0
README.rst

@@ -25,6 +25,10 @@ Build Status Tests
    :target: http://cloudbridge.readthedocs.org/en/latest/?badge=latest
    :alt: Documentation Status
 
+.. image:: https://img.shields.io/pypi/dm/cloudbridge
+   :target: https://pypistats.org/packages/cloudbridge
+   :alt: Download stats
+
 .. |aws-py38| image:: https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/nuwang/d354f151eb8c9752da13e6dec012fb07/raw/cloudbridge_py3.8_aws.json
               :target: https://github.com/CloudVE/cloudbridge/actions/
 

+ 2 - 2
cloudbridge/providers/aws/resources.py

@@ -1011,8 +1011,8 @@ class AWSNetwork(BaseNetwork):
                     wait=tenacity.wait_fixed(5),
                     reraise=True)
     def _wait_for_vpc(self):
-        self._provider.ec2_conn.meta.client.get_waiter('vpc_available').wait(
-            VpcIds=[self.id])
+        self._vpc.wait_until_exists()
+        self._vpc.wait_until_available()
 
     def wait_till_ready(self, timeout=None, interval=None):
         self._wait_for_vpc()

+ 18 - 15
cloudbridge/providers/aws/services.py

@@ -6,8 +6,6 @@ import uuid
 
 from botocore.exceptions import ClientError
 
-import tenacity
-
 import cloudbridge.base.helpers as cb_helpers
 from cloudbridge.base.middleware import dispatch
 from cloudbridge.base.resources import ClientPagedResultList
@@ -35,6 +33,7 @@ from cloudbridge.base.services import BaseVMFirewallRuleService
 from cloudbridge.base.services import BaseVMFirewallService
 from cloudbridge.base.services import BaseVMTypeService
 from cloudbridge.base.services import BaseVolumeService
+from cloudbridge.interfaces import TestMockHelperMixin
 from cloudbridge.interfaces.exceptions import DuplicateResourceException
 from cloudbridge.interfaces.exceptions import \
     InvalidConfigurationException
@@ -205,6 +204,10 @@ class AWSVMFirewallService(BaseVMFirewallService):
                                   },
                               ]
                               )
+        # workaround bug in moto security groups which doesn't yet support TagSpecifications
+        if isinstance(self.provider, TestMockHelperMixin):
+            obj.label = label
+            obj.description = description
         return obj
 
     @dispatch(event="provider.security.vm_firewalls.find",
@@ -1330,19 +1333,19 @@ class AWSGatewayService(BaseGatewayService):
         if gtw:
             return gtw[0]  # There can be only one gtw attached to a VPC
         # Gateway does not exist so create one and attach to the supplied net
-        cb_gateway = self.svc.create('create_internet_gateway')
-
-        @tenacity.retry(stop=tenacity.stop_after_attempt(5),
-                        retry=tenacity.retry_if_exception_type(ClientError),
-                        wait=tenacity.wait_fixed(5),
-                        reraise=True)
-        def _set_tag(gateway):
-            gateway._gateway.create_tags(
-                Tags=[{'Key': 'Name',
-                       'Value': AWSInternetGateway.CB_DEFAULT_INET_GATEWAY_NAME
-                       }])
-
-        _set_tag(cb_gateway)
+        cb_gateway = self.svc.create('create_internet_gateway',
+                                     TagSpecifications=[
+                                         {
+                                             'ResourceType': 'internet-gateway',
+                                             'Tags': [
+                                                 {
+                                                     'Key': 'Name',
+                                                     'Value': AWSInternetGateway.CB_DEFAULT_INET_GATEWAY_NAME
+                                                 }
+                                             ]
+                                         }
+                                     ]
+                                     )
         cb_gateway._gateway.attach_to_vpc(VpcId=network_id)
         return cb_gateway