Exemple #1
0
    def test_resize_action(self, update_mock):
        p = self.load_policy({
            'name': 'resize-sqldatabase',
            'resource': 'azure.sqldatabase',
            'filters': [
                {
                    'type': 'value',
                    'key': 'name',
                    'value': 'cctestdb'
                }
            ],
            'actions': [
                {
                    'type': 'resize',
                    'tier': 'Standard',
                    'capacity': 100,
                    'max_size_bytes': 21474836480
                }
            ],
        })

        self.resources = p.run()
        self.assertEqual(len(self.resources), 1)
        self.assertEqual(self.resources[0]['name'], 'cctestdb')

        parent_id = ResourceIdParser.get_resource_name(self.resources[0]['c7n:parent-id'])
        expected_db_update = DatabaseUpdate(sku=Sku(capacity=100, tier='Standard', name='Standard'),
                                            max_size_bytes=21474836480)

        update_mock.assert_called_once()
        name, args, kwargs = update_mock.mock_calls[0]
        self.assertEqual('test_sqlserver', args[0])
        self.assertEqual(parent_id, args[1])
        self.assertEqual('cctestdb', args[2])
        self.assertEqual(expected_db_update, args[3])
Exemple #2
0
 def _process_resource(self, database):
     sku = Sku(capacity=self.capacity, tier=self.tier, name=self.tier)
     max_size_bytes = self.max_size_bytes if not 0 else database[
         'properties']['maxSizeBytes']
     self.client.databases.update(
         database['resourceGroup'],
         ResourceIdParser.get_resource_name(database['c7n:parent-id']),
         database['name'],
         DatabaseUpdate(sku=sku, max_size_bytes=max_size_bytes))
    def test_resize_action(self):
        p = self.load_policy({
            'name':
            'resize-sqldatabase',
            'resource':
            'azure.sqldatabase',
            'filters': [{
                'type': 'value',
                'key': 'name',
                'value': 'cctestdb'
            }],
            'actions': [{
                'type': 'resize',
                'tier': 'Standard',
                'capacity': 100,
                'max_size_bytes': 21474836480
            }],
        })

        self.resources = p.run()
        self.assertEqual(len(self.resources), 1)
        self.assertEqual(self.resources[0]['name'], 'cctestdb')

        updated_database = self.client.databases.get(
            'test_sqlserver',
            ResourceIdParser.get_resource_name(
                self.resources[0]['c7n:parent-id']), 'cctestdb')

        self.assertEqual(updated_database.sku.capacity, 100)
        self.assertEqual(updated_database.sku.tier, 'Standard')
        # The value for max_size_bytes returned by api is stale,
        # so we can't make an assertion until it's fixed
        # self.assertEqual(database.max_size_bytes, 21474836480)

        # Revert action
        self.client.databases.update(
            'test_sqlserver',
            ResourceIdParser.get_resource_name(
                self.resources[0]['c7n:parent-id']), 'cctestdb',
            DatabaseUpdate(sku=Sku(capacity=125,
                                   tier='Premium',
                                   name='Premium'),
                           max_size_bytes=2147483648))