Exemplo n.º 1
0
    def test_get_blob_client_from_storage_account_without_sas(self):
        account = self.setup_account()
        resource_group = ResourceIdParser.get_resource_group(account.id)
        blob_client = StorageUtilities.get_blob_client_from_storage_account(
            resource_group, account.name, self.session)

        self.assertIsNotNone(blob_client)
    def test_get_blob_client_from_storage_account_without_sas(self):
        account = self.setup_account()
        resource_group = ResourceIdParser.get_resource_group(account.id)
        blob_client = StorageUtilities.get_blob_client_from_storage_account(
            resource_group,
            account.name,
            self.session)

        self.assertIsNotNone(blob_client)
Exemplo n.º 3
0
    def test_get_blob_client_from_storage_account_without_sas_fails_sas_generation(self):
        with self.assertRaises(ValueError):
            account = self.setup_account()
            resource_group = ResourceIdParser.get_resource_group(account.id)
            blob_client = StorageUtilities.get_blob_client_from_storage_account(
                resource_group,
                account.name,
                self.session)

            # create container for package
            blob_client.create_container('test')
            blob_client.create_blob_from_text('test', 'test.txt', 'My test contents.')
            blob_client.generate_blob_shared_access_signature('test', 'test.txt')
Exemplo n.º 4
0
    def test_get_blob_client_from_storage_account_with_sas(self):
        account = self.setup_account()
        resource_group = ResourceIdParser.get_resource_group(account.id)
        blob_client = StorageUtilities.get_blob_client_from_storage_account(
            resource_group, account.name, self.session, True)

        # create sas token for blob
        blob_client.create_container('test')
        blob_client.create_blob_from_text('test', 'test.txt',
                                          'My test contents.')
        sas = blob_client.generate_blob_shared_access_signature(
            'test', 'test.txt')

        self.assertIsNotNone(sas)
    def test_get_blob_client_from_storage_account_with_sas(self):
        account = self.setup_account()
        resource_group = ResourceIdParser.get_resource_group(account.id)
        blob_client = StorageUtilities.get_blob_client_from_storage_account(
            resource_group,
            account.name,
            self.session,
            True)

        # create sas token for blob
        blob_client.create_container('test')
        blob_client.create_blob_from_text('test', 'test.txt', 'My test contents.')
        sas = blob_client.generate_blob_shared_access_signature('test', 'test.txt')

        self.assertIsNotNone(sas)
Exemplo n.º 6
0
    def publish_functions_package(cls, function_params, package):
        session = local_session(Session)
        web_client = session.client('azure.mgmt.web.WebSiteManagementClient')

        cls.log.info('Publishing Function application')

        # provision using Kudu Zip-Deploy
        if not cls.is_consumption_plan(function_params):
            publish_creds = web_client.web_apps.list_publishing_credentials(
                function_params.function_app_resource_group_name,
                function_params.function_app_name).result()

            if package.wait_for_status(publish_creds):
                package.publish(publish_creds)
            else:
                cls.log.error(
                    "Aborted deployment, ensure Application Service is healthy."
                )
        # provision using WEBSITE_RUN_FROM_PACKAGE
        else:
            # fetch blob client
            blob_client = StorageUtilities.get_blob_client_from_storage_account(
                function_params.storage_account['resource_group_name'],
                function_params.storage_account['name'],
                session,
                sas_generation=True)

            # create container for package
            blob_client.create_container(FUNCTION_CONSUMPTION_BLOB_CONTAINER)

            # upload package
            blob_name = '%s.zip' % function_params.function_app_name
            blob_client.create_blob_from_path(
                FUNCTION_CONSUMPTION_BLOB_CONTAINER, blob_name,
                package.pkg.path)

            # create blob url for package
            sas = blob_client.generate_blob_shared_access_signature(
                FUNCTION_CONSUMPTION_BLOB_CONTAINER, blob_name,
                BlobPermissions.READ,
                datetime.datetime.utcnow() +
                datetime.timedelta(days=FUNCTION_PACKAGE_SAS_EXPIRY_DAYS)
                # expire in 10 years
            )
            blob_url = blob_client.make_blob_url(
                FUNCTION_CONSUMPTION_BLOB_CONTAINER, blob_name, sas_token=sas)

            # update application settings function package
            app_settings = web_client.web_apps.list_application_settings(
                function_params.function_app_resource_group_name,
                function_params.function_app_name)
            app_settings.properties['WEBSITE_RUN_FROM_PACKAGE'] = blob_url
            web_client.web_apps.update_application_settings(
                function_params.function_app_resource_group_name,
                function_params.function_app_name,
                kind=str,
                properties=app_settings.properties)

        # sync the scale controller for the Function App
        if not cls._sync_function_triggers(function_params):
            cls.log.error("Unable to sync triggers...")

        cls.log.info('Finished publishing Function application')
    def publish_functions_package(cls, function_params, package):
        session = local_session(Session)
        web_client = session.client('azure.mgmt.web.WebSiteManagementClient')

        cls.log.info('Publishing Function application')

        # provision using Kudu Zip-Deploy
        if not cls.is_consumption_plan(function_params):
            publish_creds = web_client.web_apps.list_publishing_credentials(
                function_params.function_app_resource_group_name,
                function_params.function_app_name).result()

            if package.wait_for_status(publish_creds):
                package.publish(publish_creds)
            else:
                cls.log.error("Aborted deployment, ensure Application Service is healthy.")
        # provision using WEBSITE_RUN_FROM_PACKAGE
        else:
            # fetch blob client
            blob_client = StorageUtilities.get_blob_client_from_storage_account(
                function_params.storage_account['resource_group_name'],
                function_params.storage_account['name'],
                session,
                sas_generation=True
            )

            # create container for package
            blob_client.create_container(FUNCTION_CONSUMPTION_BLOB_CONTAINER)

            # upload package
            blob_name = '%s.zip' % function_params.function_app_name
            packageToPublish = package.pkg.get_stream()
            count = os.path.getsize(package.pkg.path)

            blob_client.create_blob_from_stream(
                FUNCTION_CONSUMPTION_BLOB_CONTAINER, blob_name, packageToPublish, count)
            packageToPublish.close()

            # create blob url for package
            sas = blob_client.generate_blob_shared_access_signature(
                FUNCTION_CONSUMPTION_BLOB_CONTAINER,
                blob_name,
                BlobPermissions.READ,
                datetime.datetime.utcnow() +
                datetime.timedelta(days=FUNCTION_PACKAGE_SAS_EXPIRY_DAYS)
                # expire in 10 years
            )
            blob_url = blob_client.make_blob_url(
                FUNCTION_CONSUMPTION_BLOB_CONTAINER,
                blob_name,
                sas_token=sas)

            # update application settings function package
            app_settings = web_client.web_apps.list_application_settings(
                function_params.function_app_resource_group_name,
                function_params.function_app_name)
            app_settings.properties['WEBSITE_RUN_FROM_PACKAGE'] = blob_url
            web_client.web_apps.update_application_settings(
                function_params.function_app_resource_group_name,
                function_params.function_app_name,
                kind=str,
                properties=app_settings.properties
            )

        # sync the scale controller for the Function App
        if not cls._sync_function_triggers(function_params):
            cls.log.error("Unable to sync triggers...")

        cls.log.info('Finished publishing Function application')