def old_delete_app(self):
    """Creates OperationContract that deletes a new Spinnaker Application and validates its deletion in Azure Storage.
    """

    payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                'type': 'deleteApplication',
                'account': self.bindings['SPINNAKER_AZURE_ACCOUNT'],
                'application': {
                    'name': self.bindings['TEST_APP']
                },
                'user': '******'
            }],
            description= 'Test - delete application {app}'.format(app=self.bindings['TEST_APP']),
            application=self.bindings['TEST_APP'])

    builder = az.AzContractBuilder(self.az_observer)
    (builder.new_clause_builder(
        'Application Created', retryable_for_secs=30)
      .collect_resources(
          az_resource='storage',
          command='blob',
          args=['exists', '--container-name', 'front50',
          '--name', 'applications/'+self.bindings['TEST_APP']+'/application-metadata.json',
          '--account-name', self.bindings['azure_storage_account_name'],
          '--account-key', self.bindings['spinnaker_azure_storage_account_key']])
      .EXPECT(ov_factory.value_list_path_contains(
          'exists', jp.EQUIVALENT(False))))

    return st.OperationContract(
        self.new_post_operation(
            title='delete_app', data=payload,
            path='tasks'),
        contract=builder.build())
    def trigger_bake_and_RB_deploy_pipeline(self):
        """Create OperationContract that manually trigger the bake and deploy pipeline
        This create a new server group below the given load balancer and destroy the eldest one

        To verify the operation, we check that the spinnaker server groups
        for the given load balancer was created in correct size.
        """

        pipeline_id = self.bake_pipeline_id
        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "dryRun": False,
                "type": "manual",
                "user": "******"
            }],
            description="Test - begin bake and deploy: {pl}".format(
                pl=pipeline_id),
            application=self.TEST_APP)

        # Assuming the max remaining Asgs is 2
        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            "Has Virtual Machine Scale Set",
            retryable_for_secs=30).collect_resources(
                az_resource='vmss',
                command='list',
                args=[
                    '--resource-group',
                    '{app}-{rg}'.format(app=self.TEST_APP,
                                        rg=self.__rg_location)
                ]).EXPECT(
                    ov_factory.value_list_contains(
                        jp.DICT_MATCHES({
                            "name":
                            jp.STR_EQ(
                                '{lb}-v002'.format(lb=self.__full_lb_name))
                        }))).EXPECT(
                            ov_factory.value_list_contains(
                                jp.DICT_MATCHES({
                                    "name":
                                    jp.STR_EQ('{lb}-v001'.format(
                                        lb=self.__full_lb_name))
                                }))).EXPECT(
                                    ov_factory.value_list_excludes(
                                        jp.DICT_MATCHES({
                                            "name":
                                            jp.STR_EQ('{lb}-v000'.format(
                                                lb=self.__full_lb_name))
                                        }))))

        return st.OperationContract(
            self.new_post_operation(
                title='bake and deploy',
                data=payload,
                # TODO: cannot use v2 url: pipelines/v2/{app}/{pl}
                path='pipelines/{app}/{pl}'.format(app=self.TEST_APP,
                                                   pl=pipeline_id),
                max_wait_secs=7200),
            contract=builder.build())
Beispiel #3
0
    def delete_load_balancer(self):
        """Create OperationContract that delete the Load Balancer

        To verify the operation, we just check that the spinnaker load balancer
        for the given application was deleted.
        """

        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "cloudProvider": "azure",
                "loadBalancerName": self.__full_lb_name,
                "credentials": self.ACCOUNT,
                "region": self.__rg_location,
                "appName": self.TEST_APP,
                "type": "deleteLoadBalancer",
                "user": "******",
            }],
            description="Test - Delete load balancer: {lb}".format(
                lb=self.__full_lb_name),
            application=self.TEST_APP,
        )

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder("Load Balancer Deleted",
                                    retryable_for_secs=30).collect_resources(
                                        az_resource="network",
                                        command="application-gateway",
                                        args=[
                                            "list",
                                            "--resource-group",
                                            "{app}-{rg}".format(
                                                app=self.TEST_APP,
                                                rg=self.__rg_location),
                                        ],
                                    )
         # expected no lb
         .EXPECT(
             ov_factory.error_list_contains(
                 jp.ExceptionMatchesPredicate(
                     klass=st.CliAgentRunError,
                     regex=
                     r"(?:.* operation: Cannot find .*)|(?:.*\(.*could not be found.\).*)",
                 )))
         # or no target lb
         .OR(
             ov_factory.value_list_path_excludes(
                 "name", jp.STR_EQ(self.__full_lb_name))))

        return st.OperationContract(
            self.new_post_operation(
                title="delete_load_balancer",
                data=payload,
                path=("applications/{app}/tasks").format(app=self.TEST_APP),
                max_wait_secs=1800,
            ),
            contract=builder.build(),
        )
    def trigger_disable_and_destroy(self, sg_id='v000'):
        """Create OperationContract that manually trigger the disable and destroy pipeline

        To verify the operation, we just check that the spinnaker server group
        for the given load balancer was deleted.
        """

        pipeline_id = self.destroy_pipeline_id
        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "dryRun": False,
                "type": "manual",
                "user": "******"
            }],
            description="Test - begin disable and destroy server group: {pl}".
            format(pl=pipeline_id),
            application=self.TEST_APP)

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder("Has No Virtual Machine Scale Set",
                                    retryable_for_secs=30).collect_resources(
                                        az_resource='vmss',
                                        command='list',
                                        args=[
                                            '--resource-group',
                                            '{app}-{rg}'.format(
                                                app=self.TEST_APP,
                                                rg=self.__rg_location)
                                        ]).
         EXPECT(
             ov_factory.error_list_contains(
                 jp.ExceptionMatchesPredicate(
                     klass=st.CliAgentRunError,
                     regex=
                     r'(?:.* operation: Cannot find .*)|(?:.*\(.*could not be found.\).*)'
                 ))).OR(
                     ov_factory.value_list_excludes(
                         jp.DICT_MATCHES({
                             "name":
                             jp.STR_EQ('{lb}-{sg}'.format(
                                 lb=self.__full_lb_name, sg=sg_id))
                         }))))

        return st.OperationContract(
            self.new_post_operation(
                title='disable and destroy',
                data=payload,
                # TODO: cannot use v2 url: pipelines/v2/{app}/{pl}
                path='pipelines/{app}/{pl}'.format(app=self.TEST_APP,
                                                   pl=pipeline_id),
                max_wait_secs=3600),
            contract=builder.build())
    def delete_a_security_group(self):
        """Creates azContract for deleteServerGroup.

        To verify the operation, we just check that the spinnaker security group
        for the given application was deleted.
        """

        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "Provider": "azure",
                "appName": self.bindings["TEST_APP"],
                "region": self.bindings["TEST_AZURE_RG_LOCATION"],
                "regions": [self.bindings["TEST_AZURE_RG_LOCATION"]],
                "credentials": self.bindings["SPINNAKER_AZURE_ACCOUNT"],
                "securityGroupName": self.TEST_SECURITY_GROUP,
                "cloudProvider": "azure",
                "type": "deleteSecurityGroup",
                "user": "******",
            }],
            application=self.bindings["TEST_APP"],
            description="Delete Security Group: : " + self.TEST_SECURITY_GROUP,
        )

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder("Security Group Deleted",
                                    retryable_for_secs=30).
         collect_resources(
             az_resource="network",
             command="nsg",
             args=["list", "--resource-group", self.TEST_SECURITY_GROUP_RG],
         ).EXPECT(
             ov_factory.error_list_contains(
                 jp.ExceptionMatchesPredicate(
                     klass=st.CliAgentRunError,
                     regex=
                     "(?:.* operation: Cannot find .*)|(?:.*\(.*NotFound\).*)",
                 ))).OR(
                     ov_factory.value_list_path_excludes(
                         "name", jp.STR_EQ(self.TEST_SECURITY_GROUP))))

        return st.OperationContract(
            self.new_post_operation(
                title="delete_security_group",
                data=payload,
                path="applications/{app}/tasks".format(
                    app=self.bindings["TEST_APP"]),
            ),
            contract=builder.build(),
        )
    def old_create_app(self):
        """Creates OperationContract that creates a new Spinnaker Application and validate its creation in Azure Storage."""
        email = self.bindings.get("TEST_EMAIL", "*****@*****.**")
        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "type": "createApplication",
                "account": self.bindings["SPINNAKER_AZURE_ACCOUNT"],
                "application": {
                    "name": self.bindings["TEST_APP"],
                    "description": "Gate Testing Application for Azure",
                    "email": email,
                },
                "user": "******",
            }],
            description="Test - create application {app}".format(
                app=self.bindings["TEST_APP"]),
            application=self.bindings["TEST_APP"],
        )

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            "Application Created", retryable_for_secs=30).collect_resources(
                az_resource="storage",
                command="blob",
                args=[
                    "exists",
                    "--container-name",
                    "front50",
                    "--name",
                    "applications/" + self.bindings["TEST_APP"] +
                    "/application-metadata.json",
                    "--account-name",
                    self.bindings["azure_storage_account_name"],
                    "--account-key",
                    self.bindings["spinnaker_azure_storage_account_key"],
                ],
            ).EXPECT(
                ov_factory.value_list_path_contains("exists",
                                                    jp.EQUIVALENT(True))))

        return st.OperationContract(
            self.new_post_operation(title="create_app",
                                    data=payload,
                                    path="tasks"),
            contract=builder.build(),
        )
 def test_contract(self):
     """
     Create an OperationContract to trigger the builder.
     """
     builder = az.AzContractBuilder(self.az_observer)
     (builder.new_clause_builder(
         "Has Virtual Machine Scale Set",
         retryable_for_secs=30).collect_resources(
             az_resource='vmss',
             command='list',
             args=[
                 '--resource-group',
                 '{app}-{rg}'.format(app=self.TEST_APP,
                                     rg=self.__rg_location)
             ]).EXPECT(
                 ov_factory.value_list_contains(
                     jp.DICT_MATCHES({
                         "name":
                         jp.STR_EQ(
                             '{lb}-v002'.format(lb=self.__full_lb_name))
                     }))).EXPECT(
                         ov_factory.value_list_contains(
                             jp.DICT_MATCHES({
                                 "name":
                                 jp.STR_EQ('{lb}-v001'.format(
                                     lb=self.__full_lb_name))
                             }))).EXPECT(
                                 ov_factory.value_list_excludes(
                                     jp.DICT_MATCHES({
                                         "name":
                                         jp.STR_EQ('{lb}-v000'.format(
                                             lb=self.__full_lb_name))
                                     }))))
     return st.OperationContract(self.new_post_operation(title="test",
                                                         data='',
                                                         path='/'),
                                 contract=builder.build())
Beispiel #8
0
    def old_create_app(self):
        """Creates OperationContract that creates a new Spinnaker Application and validate its creation in Azure Storage.
    """
        email = self.bindings.get('TEST_EMAIL', '*****@*****.**')
        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                'type': 'createApplication',
                'account': self.bindings['SPINNAKER_AZURE_ACCOUNT'],
                'application': {
                    'name': self.bindings['TEST_APP'],
                    'description': 'Gate Testing Application for Azure',
                    'email': email
                },
                'user': '******'
            }],
            description='Test - create application {app}'.format(
                app=self.bindings['TEST_APP']),
            application=self.bindings['TEST_APP'])

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            'Application Created', retryable_for_secs=30).collect_resources(
                az_resource='storage',
                command='blob',
                args=[
                    'exists', '--container-name', 'front50', '--name',
                    'applications/' + self.bindings['TEST_APP'] +
                    '/application-metadata.json', '--account-name',
                    self.bindings['azure_storage_account_name'],
                    '--account-key',
                    self.bindings['spinnaker_azure_storage_account_key']
                ]).contains_path_eq('exists', True))

        return st.OperationContract(self.new_post_operation(title='create_app',
                                                            data=payload,
                                                            path='tasks'),
                                    contract=builder.build())
Beispiel #9
0
    def delete_a_security_group(self):
        """Creates azContract for deleteServerGroup.

    To verify the operation, we just check that the spinnaker security group
    for the given application was deleted.
    """

        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "Provider": "azure",
                "appName": self.bindings['TEST_APP'],
                "region": self.bindings['TEST_AZURE_RG_LOCATION'],
                "regions": [self.bindings['TEST_AZURE_RG_LOCATION']],
                "credentials": self.bindings['SPINNAKER_AZURE_ACCOUNT'],
                "securityGroupName": self.TEST_SECURITY_GROUP,
                "cloudProvider": "azure",
                "type": "deleteSecurityGroup",
                "user": "******"
            }],
            application=self.bindings['TEST_APP'],
            description='Delete Security Group: : ' + self.TEST_SECURITY_GROUP)

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            'Security Group Deleted', retryable_for_secs=30).collect_resources(
                az_resource='network',
                command='nsg',
                args=['list', '--resource-group', self.TEST_SECURITY_GROUP_RG],
                no_resources_ok=True).excludes_path_eq(
                    'name', self.TEST_SECURITY_GROUP))

        return st.OperationContract(self.new_post_operation(
            title='delete_security_group',
            data=payload,
            path='applications/{app}/tasks'.format(
                app=self.bindings['TEST_APP'])),
                                    contract=builder.build())
    def create_application_gateway(self):
        """Create OperationContract that create a new Application gateway

        To verify the operation, we just check that the spinnaker load balancer
        for the given application was created.
        """
        self.__lb_type = "Azure Application Gateway"
        healthyCheck = [{
            "probeName":
            "{lb}-probe".format(lb=self.__full_lb_name),
            "probeProtocol":
            "HTTP",
            "probePort":
            "80",
            "probePath":
            "/",
            "probeInterval":
            30,
            "unhealthyThreshold":
            8,
            "timeout":
            120
        }]
        rules = [{
            "ruleName": "{lb}-rule0".format(lb=self.__full_lb_name),
            "protocol": "HTTP",
            "externalPort": 80,
            "backendPort": 80,
            "probeName": "{lb}-probe".format(lb=self.__full_lb_name),
            "persistence": "None",
            "idleTimeout": 4
        }]
        subnets = [{
            "account":
            self.ACCOUNT,
            "addressPrefix":
            self.__subnet[0]['ADDRESS'],
            "device": [],
            "id":
            '/subscriptions/{id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{name}'
            .format(id=self.__subscription_id,
                    rg=self.__rg_name,
                    vnet=self.__vnet_name,
                    name=self.__subnet[0]['NAME']),
            "name":
            self.__subnet[0]['NAME'],
            "purpose":
            'TBD',
            "region":
            self.__rg_location,
            "type":
            'azure',
            "vnet":
            self.__vnet_name
        }, {
            "account":
            self.ACCOUNT,
            "addressPrefix":
            self.__subnet[1]['ADDRESS'],
            "device": [],
            "id":
            '/subscriptions/{id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{name}'
            .format(id=self.__subscription_id,
                    rg=self.__rg_name,
                    vnet=self.__vnet_name,
                    name=self.__subnet[1]['NAME']),
            "name":
            self.__subnet[1]['NAME'],
            "purpose":
            'TBD',
            "region":
            self.__rg_location,
            "type":
            'azure',
            "vnet":
            self.__vnet_name
        }]
        vnet = {
            "account": self.ACCOUNT,
            "cloudProvider": "azure",
            "id": self.__vnet_name,
            "name": self.__vnet_name,
            "region": self.__rg_location,
            "resourceGroup": self.__rg_name,
            "subnets": subnets
        }

        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "stack": self.__stack,
                "detail": self.__detail,
                "credentials": self.ACCOUNT,
                "region": self.__rg_location,
                "cloudProvider": "azure",
                "vnet": self.__vnet_name,
                "subnet": self.__subnet[1]['NAME'],
                "probes": healthyCheck,
                "securityGroups": [],
                "loadBalancingRules": rules,
                "name": self.__full_lb_name,
                "selectedVnet": vnet,
                "vnetResourceGroup": self.__rg_name,
                "selectedSubnet": subnets[1],
                "type": "upsertLoadBalancer",
                "loadBalancerType": self.__lb_type,
                "appName": self.TEST_APP,
                "loadBalancerName": self.__full_lb_name,
                "user": "******"
            }],
            description="Test - Create application gateway: {lb}".format(
                lb=self.__full_lb_name),
            application=self.TEST_APP)

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            'Application Gateway Created',
            retryable_for_secs=30).collect_resources(
                az_resource='network',
                command='application-gateway',
                args=[
                    'list', '--resource-group',
                    '{app}-{rg}'.format(app=self.TEST_APP,
                                        rg=self.__rg_location)
                ]).EXPECT(
                    ov_factory.value_list_contains(
                        jp.DICT_MATCHES({
                            'name':
                            jp.STR_EQ(self.__full_lb_name),
                            'tags':
                            jp.DICT_MATCHES({
                                'vnet':
                                jp.STR_EQ(self.__vnet_name),
                                'subnet':
                                jp.STR_EQ(self.__subnet[1]['NAME'])
                            })
                        }))))

        return st.OperationContract(self.new_post_operation(
            title="create_application_gateway",
            data=payload,
            path=('applications/{app}/tasks').format(app=self.TEST_APP),
            max_wait_secs=3600),
                                    contract=builder.build())
    def create_load_balancer(self):
        """Create OperationContract that create a new Load Balancer

        To verify the operation, we just check that the spinnaker load balancer
        for the given application was created.
        """
        self.__lb_type = "Azure Load Balancer"
        healthyCheck = [{
            "probeName":
            "{lb}-probe".format(lb=self.__full_lb_name),
            "probeProtocol":
            "TCP",
            "probePort":
            "80",
            "probeInterval":
            30,
            "unhealthyThreshold":
            8,
            "timeout":
            120
        }]
        rules = [{
            "ruleName": "{lb}-rule0".format(lb=self.__full_lb_name),
            "protocol": "TCP",
            "externalPort": 80,
            "backendPort": 80,
            "probeName": "{lb}-probe".format(lb=self.__full_lb_name),
            "persistence": "None",
            "idleTimeout": 4
        }]
        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "stack": self.__stack,
                "detail": self.__detail,
                "credentials": self.ACCOUNT,
                "region": self.__rg_location,
                "cloudProvider": "azure",
                "vnet": None,
                "subnet": None,
                "probes": healthyCheck,
                "securityGroups": [],
                "loadBalancingRules": rules,
                "name": self.__full_lb_name,
                "selectedVnet": None,
                "vnetResourceGroup": None,
                "selectedSubnet": None,
                "type": "upsertLoadBalancer",
                "loadBalancerType": self.__lb_type,
                "appName": self.TEST_APP,
                "loadBalancerName": self.__full_lb_name,
                "user": "******"
            }],
            description="Test - Create load balancer: {lb}".format(
                lb=self.__full_lb_name),
            application=self.TEST_APP)

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            'Load Balancer Created', retryable_for_secs=30).collect_resources(
                az_resource='network',
                command='lb',
                args=[
                    'list', '--resource-group',
                    '{app}-{rg}'.format(app=self.TEST_APP,
                                        rg=self.__rg_location)
                ]).EXPECT(
                    ov_factory.value_list_contains(
                        jp.DICT_MATCHES({
                            'name':
                            jp.STR_EQ(self.__full_lb_name),
                            'location':
                            jp.STR_EQ(self.__rg_location)
                        }))))

        return st.OperationContract(self.new_post_operation(
            title="create_load_balancer",
            data=payload,
            path=('applications/{app}/tasks').format(app=self.TEST_APP),
            max_wait_secs=2400),
                                    contract=builder.build())
Beispiel #12
0
    def trigger_bake_and_deploy_pipeline(self):
        """Create OperationContract that manually trigger the bake and deploy pipeline
        This create a new server group below the given load balancer.

        To verify the operation, we check that the spinnaker server group
        for the given load balancer was created in correct size.
        """

        pipeline_id = self.bake_pipeline_id
        payload = self.agent.make_json_payload_from_kwargs(
            job=[{
                "dryRun": False,
                "type": "manual",
                "user": "******"
            }],
            description="Test - begin bake and deploy: {pl}".format(
                pl=pipeline_id),
            application=self.TEST_APP,
        )

        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder(
            "Has Virtual Machine Scale Set",
            retryable_for_secs=30).collect_resources(
                az_resource="vmss",
                command="list",
                args=[
                    "--resource-group",
                    "{app}-{rg}".format(app=self.TEST_APP,
                                        rg=self.__rg_location),
                ],
            ).EXPECT(
                ov_factory.value_list_contains(
                    jp.DICT_MATCHES({
                        "name":
                        jp.STR_EQ("{lb}-v000".format(lb=self.__full_lb_name)),
                        "provisioningState":
                        jp.STR_EQ("Succeeded"),
                        "tags":
                        jp.DICT_MATCHES(
                            {"appGatewayName":
                             jp.STR_EQ(self.__full_lb_name)}),
                        "sku":
                        jp.DICT_MATCHES({
                            "name":
                            jp.STR_EQ(self.__sku["name"]),
                            "tier":
                            jp.STR_EQ(self.__sku["tier"]),
                            "capacity":
                            jp.NUM_EQ(self.__sku["capacity"]),
                        }),
                    }))))

        return st.OperationContract(
            self.new_post_operation(
                title="bake and deploy",
                data=payload,
                # TODO: cannot use v2 url: pipelines/v2/{app}/{pl}
                path="pipelines/{app}/{pl}".format(app=self.TEST_APP,
                                                   pl=pipeline_id),
                max_wait_secs=3600,
            ),
            contract=builder.build(),
        )
Beispiel #13
0
    def create_a_security_group(self):
        """Creates AzContract for createServerGroup.

        To verify the operation, we just check that the spinnaker security group
        for the given application was created.
        This will create a Network Security Group in a Resource Group on your azure Subscription
        """
        rules = [{
            "access": "Allow",
            "destinationAddressPrefix": "*",
            "destinationPortRange": "80-80",
            "direction": "InBound",
            "endPort": 80,
            "name": self.TEST_SECURITY_GROUP_RULE_1,
            "priority": 100,
            "protocol": "tcp",
            "sourceAddressPrefix": "*",
            "sourcePortRange": "*",
            "startPort": 80,
        }]
        job = [{
            "provider":
            "azure",
            "application":
            self.bindings["TEST_APP"],
            "appName":
            self.bindings["TEST_APP"],
            "region":
            self.bindings["TEST_AZURE_RG_LOCATION"],
            "stack":
            self.bindings["TEST_STACK"],
            "description":
            "Test - create security group for {app}".format(
                app=self.bindings["TEST_APP"]),
            "detail":
            "",
            "credentials":
            self.bindings["SPINNAKER_AZURE_ACCOUNT"],
            "securityRules":
            rules,
            "name":
            self.TEST_SECURITY_GROUP,
            "securityGroupName":
            self.TEST_SECURITY_GROUP,
            "cloudProvider":
            "azure",
            "type":
            "upsertSecurityGroup",
            "user":
            "******",
        }]
        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder("Security Group Created",
                                    retryable_for_secs=30).collect_resources(
                                        az_resource="network",
                                        command="nsg",
                                        args=[
                                            "show",
                                            "--name",
                                            self.TEST_SECURITY_GROUP,
                                            "--resource-group",
                                            self.TEST_SECURITY_GROUP_RG,
                                        ],
                                    ).
         EXPECT(
             ov_factory.error_list_contains(
                 jp.ExceptionMatchesPredicate(
                     klass=st.CliAgentRunError,
                     regex=
                     "(?:.* operation: Cannot find .*)|(?:.*\(.*NotFound\).*)",
                 ))).OR(
                     ov_factory.value_list_contains(
                         # sec grp name matches expected
                         jp.DICT_MATCHES({
                             "name":
                             jp.STR_SUBSTR(self.TEST_SECURITY_GROUP),
                             "securityRules":
                             jp.LIST_MATCHES(
                                 [
                                     jp.DICT_MATCHES({
                                         "protocol":
                                         jp.STR_EQ("tcp"),
                                         "name":
                                         jp.STR_EQ(
                                             self.TEST_SECURITY_GROUP_RULE_1),
                                     })
                                 ],
                                 strict=True,
                             ),
                         }))))

        payload = self.agent.make_json_payload_from_kwargs(
            job=job,
            description=" Test - create security group for {app}".format(
                app=self.bindings["TEST_APP"]),
            application=self.bindings["TEST_APP"],
        )

        return st.OperationContract(
            self.new_post_operation(
                title="create_security_group",
                data=payload,
                path="applications/{app}/tasks".format(
                    app=self.bindings["TEST_APP"]),
            ),
            contract=builder.build(),
        )
Beispiel #14
0
    def create_a_security_group(self):
        """Creates AzContract for createServerGroup.

    To verify the operation, we just check that the spinnaker security group
    for the given application was created.
    This will create a Network Security Group in a Resource Group on your azure Subscription
    """
        rules = [{
            "access": "Allow",
            "destinationAddressPrefix": "*",
            "destinationPortRange": "80-80",
            "direction": "InBound",
            "endPort": 80,
            "name": self.TEST_SECURITY_GROUP_RULE_1,
            "priority": 100,
            "protocol": "tcp",
            "sourceAddressPrefix": "*",
            "sourcePortRange": "*",
            "startPort": 80
        }]
        job = [{
            "provider":
            "azure",
            "application":
            self.bindings['TEST_APP'],
            "appName":
            self.bindings['TEST_APP'],
            "region":
            self.bindings['TEST_AZURE_RG_LOCATION'],
            "stack":
            self.bindings['TEST_STACK'],
            "description":
            "Test - create security group for {app}".format(
                app=self.bindings['TEST_APP']),
            "detail":
            "",
            "credentials":
            self.bindings['SPINNAKER_AZURE_ACCOUNT'],
            "securityRules":
            rules,
            "name":
            self.TEST_SECURITY_GROUP,
            "securityGroupName":
            self.TEST_SECURITY_GROUP,
            "cloudProvider":
            "azure",
            "type":
            "upsertSecurityGroup",
            "user":
            "******"
        }]
        builder = az.AzContractBuilder(self.az_observer)
        (builder.new_clause_builder('Security Group Created',
                                    retryable_for_secs=30).collect_resources(
                                        az_resource='network',
                                        command='nsg',
                                        args=[
                                            'show', '--name',
                                            self.TEST_SECURITY_GROUP,
                                            '--resource-group',
                                            self.TEST_SECURITY_GROUP_RG
                                        ],
                                        no_resources_ok=True)
         #sec grp name matches expected
         .contains_match({
             'name': jp.STR_SUBSTR(self.TEST_SECURITY_GROUP)
         }).contains_path_pred(
             'securityRules',
             jp.LIST_MATCHES([
                 jp.DICT_MATCHES(
                     {
                         'protocol': jp.STR_EQ('tcp'),
                         'name': jp.STR_EQ(self.TEST_SECURITY_GROUP_RULE_1)
                     })
             ],
                             strict=True),
             enumerate_terminals=False))

        payload = self.agent.make_json_payload_from_kwargs(
            job=job,
            description=' Test - create security group for {app}'.format(
                app=self.bindings['TEST_APP']),
            application=self.bindings['TEST_APP'])

        return st.OperationContract(self.new_post_operation(
            title='create_security_group',
            data=payload,
            path='applications/{app}/tasks'.format(
                app=self.bindings['TEST_APP'])),
                                    contract=builder.build())