Example #1
0
    def test__get_validated_flavor_from_context_failed(
            self, mock_flavor_resource_type_transform):
        clients = mock.MagicMock()
        clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
        config = {
            "args": {
                "flavor": {
                    "name": "test"
                }
            },
            "context": {
                "flavors": [{
                    "name": "othername",
                    "ram": 32,
                }]
            }
        }
        result = validation._get_validated_flavor(config, clients, "flavor")
        self.assertFalse(result[0].is_valid, result[0].msg)

        config = {
            "args": {
                "flavor": {
                    "name": "test"
                }
            },
        }
        result = validation._get_validated_flavor(config, clients, "flavor")
        self.assertFalse(result[0].is_valid, result[0].msg)
Example #2
0
    def test__get_validated_flavor_from_context_failed(self, mock_flavor_resource_type_transform):
        clients = mock.MagicMock()
        clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
        config = {"args": {"flavor": {"name": "test"}}, "context": {"flavors": [{"name": "othername", "ram": 32}]}}
        result = validation._get_validated_flavor(config, clients, "flavor")
        self.assertFalse(result[0].is_valid, result[0].msg)

        config = {"args": {"flavor": {"name": "test"}}}
        result = validation._get_validated_flavor(config, clients, "flavor")
        self.assertFalse(result[0].is_valid, result[0].msg)
Example #3
0
 def test__get_validated_flavor_not_found(
         self, mock_flavor_transform):
     clients = mock.MagicMock()
     clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
     result = validation._get_validated_flavor({"args": {"a": "test"}},
                                               clients, "a")
     self.assertFalse(result[0].is_valid, result[0].msg)
Example #4
0
 def test__get_validated_flavor_not_found(
         self, mock_flavor_transform):
     clients = mock.MagicMock()
     clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
     result = validation._get_validated_flavor({"args": {"a": "test"}},
                                               clients, "a")
     self.assertFalse(result[0].is_valid, result[0].msg)
Example #5
0
    def test__get_validated_flavor(self, mock_flavor_resource_type_transform):
        clients = mock.MagicMock()
        clients.nova().flavors.get.return_value = "flavor"

        result = validation._get_validated_flavor({"args": {"a": "test"}}, clients, "a")
        self.assertTrue(result[0].is_valid, result[0].msg)
        self.assertEqual(result[1], "flavor")
        mock_flavor_resource_type_transform.assert_called_once_with(clients=clients, resource_config="test")
        clients.nova().flavors.get.assert_called_once_with(flavor="flavor_id")
Example #6
0
    def test__get_validated_flavor(
            self, mock_flavor_transform):
        clients = mock.MagicMock()
        clients.nova().flavors.get.return_value = "flavor"

        result = validation._get_validated_flavor({"args": {"a": "test"}},
                                                  clients, "a")
        self.assertTrue(result[0].is_valid, result[0].msg)
        self.assertEqual(result[1], "flavor")
        mock_flavor_transform.assert_called_once_with(
            clients=clients, resource_config="test")
        clients.nova().flavors.get.assert_called_once_with(flavor="flavor_id")
Example #7
0
 def test__get_validated_flavor_transform_error(
         self, mock_flavor_transform):
     result = validation._get_validated_flavor({"args": {"a": "test"}},
                                               None, "a")
     self.assertFalse(result[0].is_valid, result[0].msg)
Example #8
0
 def test__get_validated_flavor_no_value_in_config(self):
     result = validation._get_validated_flavor({}, None, "non_existing")
     self.assertFalse(result[0].is_valid, result[0].msg)
Example #9
0
 def test__get_validated_flavor_transform_error(
         self, mock_flavor_transform):
     result = validation._get_validated_flavor({"args": {"a": "test"}},
                                               None, "a")
     self.assertFalse(result[0].is_valid, result[0].msg)
Example #10
0
 def test__get_validated_flavor_no_value_in_config(self):
     result = validation._get_validated_flavor({}, None, "non_existing")
     self.assertFalse(result[0].is_valid, result[0].msg)