def test_out_of_quota(self):
        scale_set = VirtualMachineScaleSet('eastus', {}, sku=Sku('Standard_H16', capacity=1))
        scale_set.name = 'test'
        scale_set.provisioning_state = 'Succeeded'
        scale_set.id = 'fake_id'

        compute_client = mock.Mock()
        compute_client.virtual_machine_scale_sets = mock.Mock()
        compute_client.virtual_machine_scale_sets.list = mock.Mock(return_value=[scale_set])

        reason = "Operation results in exceeding quota limits of Core. Maximum allowed: 800, Current in use: 784, Additional requested: 320."
        message = "{\"error\":{\"code\":\"OperationNotAllowed\",\"message\":\"" + reason + "\"}}"
        monitor_client = mock.Mock()
        monitor_client.activity_logs = mock.Mock()
        now = datetime.now(pytz.utc)
        monitor_client.activity_logs.list = mock.Mock(return_value=[EventData('Error',
                                                                              now,
                                                                              now,
                                                                              resource_id=scale_set.id,
                                                                              status=LocalizableString('Failed'),
                                                                              properties={'statusCode': 'Conflict',
                                                                                          'statusMessage': message})])

        api = AzureWrapper(compute_client, monitor_client)
        resource_group = 'test_rg'
        expected = AzureScaleSet(scale_set.location, resource_group, scale_set.name, scale_set.sku.name, scale_set.sku.capacity,
                                 scale_set.provisioning_state, now + TIMEOUT_PERIOD, reason)
        acutal = api.list_scale_sets(resource_group)
        self.assertEqual([expected], acutal)

        compute_client.virtual_machine_scale_sets.list.assert_called_once_with(resource_group)
        monitor_client.activity_logs.list.assert_called_once()
    def test_basic(self):
        scale_set = VirtualMachineScaleSet(
            'eastus', {
                PRIORITY_TAG: '1',
                NO_SCHEDULE_TAINTS_TAG: json.dumps({'gpu': 'yes'})
            },
            sku=Sku('Standard_H16', capacity=1))
        scale_set.name = 'test'
        scale_set.provisioning_state = 'Succeeded'
        scale_set.id = 'fake_id'

        compute_client = mock.Mock()
        compute_client.virtual_machine_scale_sets = mock.Mock()
        compute_client.virtual_machine_scale_sets.list = mock.Mock(
            return_value=[scale_set])

        monitor_client = mock.Mock()
        monitor_client.activity_logs = mock.Mock()
        monitor_client.activity_logs.list = mock.Mock(return_value=[])

        api = AzureWrapper(compute_client, monitor_client, None)
        resource_group = 'test_rg'
        expected = AzureScaleSet(scale_set.location,
                                 resource_group,
                                 scale_set.name,
                                 scale_set.sku.name,
                                 scale_set.sku.capacity,
                                 scale_set.provisioning_state,
                                 priority=1,
                                 no_schedule_taints={'gpu': 'yes'})
        self.assertEqual([expected], api.list_scale_sets(resource_group))

        compute_client.virtual_machine_scale_sets.list.assert_called_once_with(
            resource_group)
        monitor_client.activity_logs.list.assert_called_once()