Example #1
0
    def test_parse_staging_image_argument(self, logger_mock,
                                          client_factory_mock):
        from msrestazure.azure_exceptions import CloudError
        compute_client = mock.MagicMock()
        resp = mock.MagicMock()
        cmd = mock.MagicMock()
        cmd.cli_ctx = DummyCli()
        resp.status_code = 404
        resp.text = '{"Message": "Not Found"}'

        compute_client.virtual_machine_images.get.side_effect = CloudError(
            resp, error='image not found')
        client_factory_mock.return_value = compute_client

        np = mock.MagicMock()
        np.location = 'some region'
        np.image = 'publisher1:offer1:sku1:1.0.0'
        np.plan_name, np.plan_publisher, np.plan_product = '', '', ''

        # action
        _parse_image_argument(cmd, np)

        # assert
        logger_mock.assert_called_with(
            "Querying the image of '%s' failed for an error '%s'. "
            "Configuring plan settings will be skipped",
            'publisher1:offer1:sku1:1.0.0', 'image not found')
Example #2
0
    def test_parse_managed_image_argument(self):
        np = mock.MagicMock()
        np.image = '/subscriptions/123/resourceGroups/foo/providers/Microsoft.Compute/images/nixos-imag.vhd'
        cmd = mock.MagicMock()

        # action & assert
        self.assertEqual(_parse_image_argument(cmd, np), 'image_id')
Example #3
0
    def test_parse_managed_image_argument(self):
        np = mock.MagicMock()
        np.image = '/subscriptions/123/resourceGroups/foo/providers/Microsoft.Compute/images/nixos-imag.vhd'
        cmd = mock.MagicMock()

        # action & assert
        self.assertEqual(_parse_image_argument(cmd, np), 'image_id')
Example #4
0
    def test_parse_image_argument(self, client_factory_mock):
        compute_client = mock.MagicMock()
        image = mock.MagicMock()
        image.plan.name = 'plan1'
        image.plan.product = 'product1'
        image.plan.publisher = 'publisher1'
        compute_client.virtual_machine_images.get.return_value = image
        client_factory_mock.return_value = compute_client

        np = mock.MagicMock()
        np.location = 'some region'
        np.image = 'publisher1:offer1:sku1:1.0.0'

        # action
        _parse_image_argument(np)

        # assert
        self.assertEqual('plan1', np.plan_name)
        self.assertEqual('product1', np.plan_product)
        self.assertEqual('publisher1', np.plan_publisher)
    def test_parse_image_argument(self, client_factory_mock):
        compute_client = mock.MagicMock()
        image = mock.MagicMock()
        image.plan.name = 'plan1'
        image.plan.product = 'product1'
        image.plan.publisher = 'publisher1'
        compute_client.virtual_machine_images.get.return_value = image
        client_factory_mock.return_value = compute_client

        np = mock.MagicMock()
        np.location = 'some region'
        np.image = 'publisher1:offer1:sku1:1.0.0'

        # action
        _parse_image_argument(np)

        # assert
        self.assertEqual('plan1', np.plan_name)
        self.assertEqual('product1', np.plan_product)
        self.assertEqual('publisher1', np.plan_publisher)
Example #6
0
    def test_parse_staging_image_argument(self, logger_mock, client_factory_mock):
        compute_client = mock.MagicMock()
        resp = mock.MagicMock()
        resp.status_code = 404
        resp.text = '{"Message": "Not Found"}'

        compute_client.virtual_machine_images.get.side_effect = CloudError(resp, error='image not found')
        client_factory_mock.return_value = compute_client

        np = mock.MagicMock()
        np.location = 'some region'
        np.image = 'publisher1:offer1:sku1:1.0.0'

        # action
        _parse_image_argument(np)

        # assert
        logger_mock.assert_called_with("Querying the image of '%s' failed for an error '%s'. "
                                       "Configuring plan settings will be skipped", 'publisher1:offer1:sku1:1.0.0',
                                       'image not found')
Example #7
0
 def test_parse_unmanaged_image_argument(self):
     np = mock.MagicMock()
     np.image = 'https://foo.blob.core.windows.net/vhds/1'
     cmd = mock.MagicMock()
     # action & assert
     self.assertEqual(_parse_image_argument(cmd, np), 'uri')
Example #8
0
 def test_parse_unmanaged_image_argument(self):
     np = mock.MagicMock()
     np.image = 'https://foo.blob.core.windows.net/vhds/1'
     cmd = mock.MagicMock()
     # action & assert
     self.assertEqual(_parse_image_argument(cmd, np), 'uri')