Beispiel #1
0
    def provision(self):
        """Provision any resources needed for the policy."""
        existing_service_plan = self.client.app_service_plans.get(
            self.group_name, self.parameters['servicePlanName']['value'])

        if not existing_service_plan:
            self.template_util.create_resource_group(
                self.group_name, {'location': self.parameters['location']['value']})

            self.template_util.deploy_resource_template(
                self.group_name, 'dedicated_functionapp.json', self.parameters).wait()

        else:
            existing_webapp = self.client.web_apps.get(self.group_name, self.webapp_name)
            if not existing_webapp:
                functionapp_util = FunctionAppUtilities()
                functionapp_util.deploy_webapp(self.webapp_name,
                                               self.group_name, existing_service_plan,
                                               self.parameters['storageName']['value'])
            else:
                self.log.info("Found existing App %s (%s) in group %s" %
                              (self.webapp_name, existing_webapp.location, self.group_name))

        self.log.info("Building function package for %s" % self.webapp_name)

        archive = FunctionPackage(self.policy_name)
        archive.build(self.policy.data)
        archive.close()

        self.log.info("Function package built, size is %dMB" % (archive.pkg.size / (1024 * 1024)))

        if archive.wait_for_status(self.webapp_name):
            archive.publish(self.webapp_name)
        else:
            self.log.error("Aborted deployment, ensure Application Service is healthy.")
class FunctionAppUtilsTest(BaseTest):
    def setUp(self):
        super(FunctionAppUtilsTest, self).setUp()
        self.functionapp_util = FunctionAppUtilities()

    @arm_template('functionapp-reqs.json')
    def test_get_storage_connection_string(self):
        storage_name = 'cloudcustodiantest'
        conn_string = self.functionapp_util.get_storage_connection_string(
            CONST_GROUP_NAME, storage_name)

        self.assertIn('AccountName=%s;' % storage_name, conn_string)

    @arm_template('functionapp-reqs.json')
    def test_get_application_insights_key_exists(self):
        app_insights_name = 'cloud-custodian-test'
        key = self.functionapp_util.get_application_insights_key(
            CONST_GROUP_NAME, app_insights_name)

        self.assertIsNotNone(key)

    @arm_template('functionapp-reqs.json')
    def test_get_application_insights_key_not_exists(self):
        app_insights_name = 'does-not-exist'
        key = self.functionapp_util.get_application_insights_key(
            CONST_GROUP_NAME, app_insights_name)

        self.assertFalse(key)

    @arm_template('functionapp-reqs.json')
    def test_deploy_webapp(self):
        s = Session()
        web_client = s.client('azure.mgmt.web.WebSiteManagementClient')

        service_plan = web_client.app_service_plans.get(
            CONST_GROUP_NAME, 'cloud-custodian-test')
        self.assertIsNotNone(service_plan)
        webapp_name = 'test-deploy-webapp'
        self.functionapp_util.deploy_webapp(webapp_name,
                                            CONST_GROUP_NAME,
                                            service_plan,
                                            'cloudcustodiantest')

        wep_app = web_client.web_apps.get(CONST_GROUP_NAME, webapp_name)
        self.assertIsNotNone(wep_app)
class FunctionAppUtilsTest(BaseTest):
    def setUp(self):
        super(FunctionAppUtilsTest, self).setUp()
        self.functionapp_util = FunctionAppUtilities()

    @arm_template('functionapp-reqs.json')
    def test_get_storage_connection_string(self):
        storage_name = 'cloudcustodiantest'
        conn_string = self.functionapp_util.get_storage_connection_string(
            CONST_GROUP_NAME, storage_name)

        self.assertIn('AccountName=%s;' % storage_name, conn_string)

    @arm_template('functionapp-reqs.json')
    def test_get_application_insights_key_exists(self):
        app_insights_name = 'cloud-custodian-test'
        key = self.functionapp_util.get_application_insights_key(
            CONST_GROUP_NAME, app_insights_name)

        self.assertIsNotNone(key)

    @arm_template('functionapp-reqs.json')
    def test_get_application_insights_key_not_exists(self):
        app_insights_name = 'does-not-exist'
        key = self.functionapp_util.get_application_insights_key(
            CONST_GROUP_NAME, app_insights_name)

        self.assertFalse(key)

    @arm_template('functionapp-reqs.json')
    def test_deploy_webapp(self):
        s = Session()
        web_client = s.client('azure.mgmt.web.WebSiteManagementClient')

        service_plan = web_client.app_service_plans.get(
            CONST_GROUP_NAME, 'cloud-custodian-test')
        self.assertIsNotNone(service_plan)
        webapp_name = 'test-deploy-webapp'
        self.functionapp_util.deploy_webapp(webapp_name, CONST_GROUP_NAME,
                                            service_plan, 'cloudcustodiantest')

        wep_app = web_client.web_apps.get(CONST_GROUP_NAME, webapp_name)
        self.assertIsNotNone(wep_app)
Beispiel #4
0
    def provision(self):
        """Provision any resources needed for the policy."""
        template_util = TemplateUtilities()

        parameters = self._get_parameters(template_util)
        group_name = parameters['servicePlanName']['value']
        webapp_name = parameters['name']['value']
        policy_name = self.policy.data['name'].replace(' ', '-').lower()

        existing_service_plan = self.client.app_service_plans.get(
            group_name, parameters['servicePlanName']['value'])

        if not existing_service_plan:
            template_util.create_resource_group(
                group_name, {'location': parameters['location']['value']})

            template_util.deploy_resource_template(
                group_name, 'dedicated_functionapp.json', parameters).wait()

        else:
            existing_webapp = self.client.web_apps.get(group_name, webapp_name)
            if not existing_webapp:
                functionapp_util = FunctionAppUtilities()
                functionapp_util.deploy_webapp(
                    webapp_name, group_name, existing_service_plan,
                    parameters['storageName']['value'])
            else:
                self.log.info(
                    "Found existing App %s (%s) in group %s" %
                    (webapp_name, existing_webapp.location, group_name))

        self.log.info("Building function package for %s" % webapp_name)

        archive = FunctionPackage(policy_name)
        archive.build(self.policy.data)
        archive.close()

        if archive.wait_for_status(webapp_name):
            archive.publish(webapp_name)
        else:
            self.log.error(
                "Aborted deployment, ensure Application Service is healthy.")
Beispiel #5
0
    def provision(self):
        """Provision any resources needed for the policy."""
        template_util = TemplateUtilities()

        parameters = self._get_parameters(template_util)
        group_name = parameters['servicePlanName']['value']
        webapp_name = parameters['name']['value']
        policy_name = self.policy.data['name'].replace(' ', '-').lower()

        existing_service_plan = self.client.app_service_plans.get(
            group_name, parameters['servicePlanName']['value'])

        if not existing_service_plan:
            template_util.create_resource_group(
                group_name, {'location': parameters['location']['value']})

            template_util.deploy_resource_template(
                group_name, 'dedicated_functionapp.json', parameters).wait()

        else:
            existing_webapp = self.client.web_apps.get(group_name, webapp_name)
            if not existing_webapp:
                functionapp_util = FunctionAppUtilities()
                functionapp_util.deploy_webapp(webapp_name, group_name, existing_service_plan,
                                               parameters['storageName']['value'])
            else:
                self.log.info("Found existing App %s (%s) in group %s" %
                              (webapp_name, existing_webapp.location, group_name))

        self.log.info("Building function package for %s" % webapp_name)

        archive = FunctionPackage(policy_name)
        archive.build(self.policy.data)
        archive.close()

        if archive.wait_for_status(webapp_name):
            archive.publish(webapp_name)
        else:
            self.log.error("Aborted deployment, ensure Application Service is healthy.")