def test_delete_storage(self):
        ctx = self.mock_ctx('testdeletestorage')
        current_ctx.set(ctx=ctx)
        ctx.logger.info("BEGIN test delete storage")

        status_code = storage.create(ctx=ctx)
        ctx.logger.info("status_code : " + str(status_code))
        self.assertTrue(bool((status_code == 200) | (status_code == 202)))
        current_ctx.set(ctx=ctx)
        utils.wait_status(ctx, "storage",constants.SUCCEEDED, timeout=600)

        ctx.logger.info("create storage with deletable propertie set to False")
        ctx.node.properties[constants.DELETABLE_KEY] = False
        
        ctx.logger.info("not delete storage")
        self.assertEqual(0, storage.delete(ctx=ctx))

        ctx.logger.info("Set deletable propertie to True")
        ctx.node.properties[constants.DELETABLE_KEY] = True

        ctx.logger.info("Delete storage")
        self.assertEqual(200, storage.delete(ctx=ctx))

        ctx.logger.info("Checking Storage Account deleted")
        current_ctx.set(ctx=ctx)
        self.assertRaises(utils.WindowsAzureError,
            storage.get_provisioning_state,
            ctx=ctx
        )
        ctx.logger.info("Storage Account Deleted")

        ctx.logger.info("END test delete storage")
    def test_create_storage(self):
        ctx = self.mock_ctx('testcreatestorage')
        current_ctx.set(ctx=ctx)
        ctx.logger.info("BEGIN test create storage")
    
        status_code = storage.create(ctx=ctx)
        ctx.logger.info("status_code : " + str(status_code))
        self.assertTrue(bool((status_code == 200) | (status_code == 202)))
        current_ctx.set(ctx=ctx)
        utils.wait_status(ctx, "storage",constants.SUCCEEDED, timeout=600)
        ctx.logger.info("Storage Account Created")

        keys = storage.get_storage_keys(ctx)
        self.assertIsNotNone(keys)
        self.assertEqual(len(keys), 2)
        ctx.logger.info("Key 1: {}, key 2: {}".format(keys[0], keys[1]))

        self.assertEqual(200, storage.delete(ctx=ctx))
        ctx.logger.info("Checking Storage Account deleted")
        current_ctx.set(ctx=ctx)
        self.assertRaises(utils.WindowsAzureError,
            storage.get_provisioning_state,
            ctx=ctx
        )
        ctx.logger.info("Storage Account Deleted")

        ctx.logger.info("END test create storage")
    def test_conflict_storage(self):
        ctx = self.mock_ctx('testconflictstorage')
        current_ctx.set(ctx=ctx)
        ctx.logger.info("BEGIN test conflict storage")

        status_code = storage.create(ctx=ctx)
        ctx.logger.info("status_code : " + str(status_code))
        self.assertTrue(bool((status_code == 200) | (status_code == 202)))
        current_ctx.set(ctx=ctx)
        utils.wait_status(ctx, "storage", constants.SUCCEEDED, timeout=600)
        ctx.logger.info("Storage Account Created")

        ctx.logger.info("Conflict Creating Storage Account")
        self.assertEqual(409, storage.create(ctx=ctx))

        self.assertEqual(200, storage.delete(ctx=ctx))

        ctx.logger.info("Check is Storage Account is release")
        current_ctx.set(ctx=ctx)
        self.assertRaises(utils.WindowsAzureError,
            storage.get_provisioning_state,
            ctx=ctx
        )
        ctx.logger.info("Storage Account Deleted")

        ctx.logger.info("END test conflict storage")
    def test_datadisk_in_storage_account(self):
        disk = [{'name': 'attach_disk',
                  'size': 100,
                  'deletable': False,
                  'caching': 'None'
                }]

        test_name = 'test-datadisk-in-storage-account'
        ctx = self.mock_ctx(test_name, disk)

        current_ctx.set(ctx=ctx)
        ctx.logger.info("CREATE storage account")
        ctx.node.properties[constants.ACCOUNT_TYPE_KEY] = "Standard_LRS"
        ctx.node.properties[constants.STORAGE_ACCOUNT_KEY] = \
            "storageaccountdisk" + self.__random_id
        storage.create(ctx=ctx)
        current_ctx.set(ctx=ctx)
        utils.wait_status(ctx, "storage",constants.SUCCEEDED, timeout=600)

        current_ctx.set(ctx=ctx)
        ctx.logger.info("BEGIN create VM test: {}".format(test_name))

        instance.create(ctx=ctx)
        
        ctx.instance.relationships.append(
                    MockRelationshipContext(
                                'test',
                                {constants.STORAGE_ACCOUNT_KEY: \
                                       'storageaccountdisk' + self.__random_id
                                }, 
                                constants.DISK_CONTAINED_IN_STORAGE_ACCOUNT
                    )
        )
                                            
        current_ctx.set(ctx=ctx)
        datadisks.create(ctx=ctx)

        current_ctx.set(ctx=ctx)
        utils.wait_status(ctx, 'instance',timeout=900)

        jsonInstance = instance.get_json_from_azure(ctx=ctx)

        self.assertIn('storageaccountdisk' + self.__random_id,
                      jsonInstance['properties'
                                   ]['storageProfile'
                                     ]['dataDisks'][0]['vhd']['uri']
                      )

        ctx.logger.info('Disks are located in {}.'.format(
                                    'storageaccountdisk' + self.__random_id,
                                    )
                        )

        current_ctx.set(ctx=ctx)
        ctx.logger.info("BEGIN delete VM test: {}".format(test_name))
        instance.delete(ctx=ctx)

        try:
            current_ctx.set(ctx=ctx)
            utils.wait_status(ctx, 'instance', 
                              constants.DELETING, timeout=900)
        except utils.WindowsAzureError:
            pass

        current_ctx.set(ctx=ctx)
        ctx.logger.info("DELETE storage account")
        ctx.node.properties[constants.ACCOUNT_TYPE_KEY] = "Standard_LRS"
        ctx.node.properties[constants.STORAGE_ACCOUNT_KEY] = \
            "storageaccountdisk" + self.__random_id
        storage.delete(ctx=ctx)