コード例 #1
0
    def test_recommendations(self):
        # List should return at least one recommendation with filters
        output = self.cmd('advisor recommendation list --category Security',
                          checks=self.check("[0].category", 'Security')).get_output_in_json()

        # Set the recommendation details to use with further commands
        rec = output[0]
        name = rec['name']
        recommendation_id = rec['id']
        resource_id = _parse_recommendation_uri(recommendation_id)
        self.kwargs.update({
            'name': name,
            'recommendation_id': recommendation_id,
            'resource_id': resource_id
        })

        # Disable with specified duration should create a suppression
        self.cmd('advisor recommendation disable --ids {recommendation_id} --days 1',
                 checks=[self.check("[0].id", recommendation_id),
                         self.exists("[0].suppressionIds")])

        # Disable again should create another suppression
        self.cmd('advisor recommendation disable --ids {recommendation_id}',
                 checks=[self.check("[0].id", recommendation_id),
                         self.greater_than("length([0].suppressionIds)", 1)])

        # Enable should remove all suppressions
        self.cmd('advisor recommendation enable --ids {recommendation_id}',
                 checks=[self.check("[0].id", recommendation_id),
                         self.check("[0].suppressionIds", None)])

        # Enable again should be a no op
        self.cmd('advisor recommendation enable --ids {recommendation_id}',
                 checks=[self.check("[0].id", recommendation_id),
                         self.check("[0].suppressionIds", None)])
コード例 #2
0
 def test__parse_recommendation_uri(self):
     recommendation_uri = ("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo"
                           "/providers/Microsoft.Network/expressRouteCircuits/test/"
                           "providers/Microsoft.Advisor/recommendations/c4deb869-ea38-f90d-331f-91770021d425"
                           "/suppressions/5c9c3fce-c1b2-7e45-106c-152ce3c04be5")
     result = _parse_recommendation_uri(recommendation_uri)
     self.assertEqual(
         result['resource_uri'],
         ("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo"
          "/providers/Microsoft.Network/expressRouteCircuits/test"))
     self.assertEqual(result['recommendation_id'], 'c4deb869-ea38-f90d-331f-91770021d425')
コード例 #3
0
    def test_recommendations_resource_group(self):
        resource_group = 'cli-live-test-rg'
        self.kwargs.update({'resource_group': resource_group})

        # List should return at least one recommendation with filters
        output = self.cmd(
            'advisor recommendation list --resource-group {resource_group}',
            checks=self.check("[0].resourceGroup",
                              resource_group)).get_output_in_json()

        # Set the recommendation details to use with further commands
        resource_id = _parse_recommendation_uri(
            output[0]['id'])['resource_uri']
        name = output[0]['name']
        self.kwargs.update({'resource_id': resource_id, 'name': name})

        # Disable with specified duration should create a suppression
        self.cmd(
            'advisor recommendation disable -n {name} -g {resource_group} --days 1',
            checks=[
                self.check("[0].name", name),
                self.check("[0].resourceGroup", resource_group),
                self.exists("[0].suppressionIds")
            ])

        # Disable again should create another suppression
        self.cmd(
            'advisor recommendation disable -n {name} -g {resource_group}',
            checks=[
                self.check("[0].name", name),
                self.check("[0].resourceGroup", resource_group),
                self.greater_than("length([0].suppressionIds)", 1)
            ])

        # Enable should remove all suppressions
        self.cmd('advisor recommendation enable -n {name} -g {resource_group}',
                 checks=[
                     self.check("[0].name", name),
                     self.check("[0].resourceGroup", resource_group),
                     self.check("[0].suppressionIds", None)
                 ])

        # Enable again should be a no op
        self.cmd('advisor recommendation enable -n {name} -g {resource_group}',
                 checks=[
                     self.check("[0].name", name),
                     self.check("[0].resourceGroup", resource_group),
                     self.check("[0].suppressionIds", None)
                 ])
コード例 #4
0
    def test_recommendations_resource_group(self):
        resource_group = 'AzExpertStg'
        self.kwargs.update({
            'resource_group': resource_group
        })

        # List should return at least one recommendation with filters
        output = self.cmd('advisor recommendation list --resource-group {resource_group}',
                          checks=self.check("[0].resourceGroup", resource_group)).get_output_in_json()

        # Set the recommendation details to use with further commands
        resource_id = _parse_recommendation_uri(output[0]['id'])['resource_uri']
        name = output[0]['name']
        self.kwargs.update({
            'resource_id': resource_id,
            'name': name
        })

        # Disable with specified duration should create a suppression
        self.cmd('advisor recommendation disable -n {name} -g {resource_group} --days 1',
                 checks=[self.check("[0].name", name),
                         self.check("[0].resourceGroup", resource_group),
                         self.exists("[0].suppressionIds")])

        # Disable again should create another suppression
        self.cmd('advisor recommendation disable -n {name} -g {resource_group}',
                 checks=[self.check("[0].name", name),
                         self.check("[0].resourceGroup", resource_group),
                         self.greater_than("length([0].suppressionIds)", 1)])

        # Enable should remove all suppressions
        self.cmd('advisor recommendation enable -n {name} -g {resource_group}',
                 checks=[self.check("[0].name", name),
                         self.check("[0].resourceGroup", resource_group),
                         self.check("[0].suppressionIds", None)])

        # Enable again should be a no op
        self.cmd('advisor recommendation enable -n {name} -g {resource_group}',
                 checks=[self.check("[0].name", name),
                         self.check("[0].resourceGroup", resource_group),
                         self.check("[0].suppressionIds", None)])