Bläddra i källkod

Misc fixes to azure and test improvements

Nuwan Goonasekera 8 år sedan
förälder
incheckning
d08e68c327

+ 5 - 4
cloudbridge/cloud/providers/azure/provider.py

@@ -22,7 +22,7 @@ class AzureCloudProvider(BaseCloudProvider):
         self.subscription_id = self. \
             _get_config_value('azure_subscription_id',
                               os.environ.get('AZURE_SUBSCRIPTION_ID', None))
-        self.client_Id = self._get_config_value(
+        self.client_id = self._get_config_value(
             'azure_client_id', os.environ.get('AZURE_CLIENT_ID', None))
         self.secret = self._get_config_value(
             'azure_secret', os.environ.get('AZURE_SECRET', None))
@@ -36,11 +36,12 @@ class AzureCloudProvider(BaseCloudProvider):
         self.resource_group = self._get_config_value(
             'azure_resource_group', os.environ.get('AZURE_RESOURCE_GROUP',
                                                    'cloudbridge'))
-
+        # Storage account name is limited to a max length of 24 characters
+        # so take part of the client id to keep it unique
         self.storage_account = self._get_config_value(
             'azure_storage_account',
             os.environ.get('AZURE_STORAGE_ACCOUNT',
-                           self.resource_group + 'storage'))
+                           'storageacc' + self.resource_group[-12:]))
 
         self.vm_default_user_name = self._get_config_value(
             'azure_vm_default_user_name', os.environ.get
@@ -83,7 +84,7 @@ class AzureCloudProvider(BaseCloudProvider):
 
             provider_config = {
                 'azure_subscription_id': self.subscription_id,
-                'azure_client_id': self.client_Id,
+                'azure_client_id': self.client_id,
                 'azure_secret': self.secret,
                 'azure_tenant': self.tenant,
                 'azure_region_name': self.region_name,

+ 1 - 0
cloudbridge/cloud/providers/azure/resources.py

@@ -1003,6 +1003,7 @@ class AzureFloatingIP(BaseFloatingIP):
         return self._ip.ip_configuration.private_ip_address \
             if self._ip.ip_configuration else None
 
+    @property
     def in_use(self):
         return True if self._ip.ip_configuration else False
 

+ 3 - 0
cloudbridge/cloud/providers/azure/services.py

@@ -418,6 +418,9 @@ class AzureInstanceService(BaseInstanceService):
 
         image = (self.provider.compute.images.get(image)
                  if isinstance(image, str) else image)
+        if not isinstance(image, AzureMachineImage):
+            raise Exception("Provided image %s is not a valid azure image"
+                            % image)
 
         instance_size = vm_type.id if \
             isinstance(vm_type, VMType) else vm_type

+ 1 - 1
docs/topics/setup.rst

@@ -71,7 +71,7 @@ will override environment values.
 
     ## For Azure
     config = {'azure_subscription_id': '<your_subscription_id>',
-              'azure_client_id': '<your_client_Id>',
+              'azure_client_id': '<your_client_id>',
               'azure_secret': '<your_secret>',
               'azure_tenant': '<your_tenant>',
               'azure_resource_group': '<your resource group>'}

+ 8 - 0
test/test_compute_service.py

@@ -348,6 +348,10 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                 router.attach_gateway(gateway)
                 # check whether adding an elastic ip works
                 fip = self.provider.networking.floating_ips.create()
+                self.assertFalse(
+                    fip.in_use,
+                    "Newly created floating IP address should not be in use.")
+
                 with helpers.cleanup_action(lambda: fip.delete()):
                     with helpers.cleanup_action(
                             lambda: test_inst.remove_floating_ip(fip)):
@@ -356,6 +360,10 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                         # On Devstack, FloatingIP is listed under private_ips.
                         self.assertIn(fip.public_ip, test_inst.public_ips +
                                       test_inst.private_ips)
+                        fip.refresh()
+                        self.assertTrue(
+                            fip.in_use,
+                            "Attached floating IP address should be in use.")
                     test_inst.refresh()
                     self.assertNotIn(
                         fip.public_ip,