コード例 #1
0
    def test_setup_with_service_name(self):
        self.mock_kc.services.list.return_value = [
            utils.Struct(type="computev21", name="NovaV21")
        ]
        name = api_versions.OpenStackAPIVersions.get_fullname()
        context = {
            "config": {
                name: {
                    "nova": {
                        "service_name": "NovaV21"
                    }
                }
            },
            "admin": {
                "credential": mock.MagicMock()
            },
            "users": [{
                "credential": mock.MagicMock()
            }]
        }
        ctx = api_versions.OpenStackAPIVersions(context)
        ctx.setup()

        self.service_catalog.get_endpoints.assert_called_once_with()
        self.mock_kc.services.list.assert_called_once_with()

        versions = ctx.context["config"]["api_versions@openstack"]
        self.assertEqual("computev21", versions["nova"]["service_type"])
コード例 #2
0
 def test_setup_with_wrong_service_type(self):
     context_obj = {
         "config": {
             api_versions.OpenStackAPIVersions.get_fullname(): {
                 "nova": {
                     "service_type": "service_type"
                 }
             }
         },
         "users": [{
             "credential": mock.MagicMock()
         }]
     }
     ctx = api_versions.OpenStackAPIVersions(context_obj)
     self.assertRaises(exceptions.ValidationError, ctx.setup)
     self.service_catalog.get_endpoints.assert_called_once_with()
コード例 #3
0
 def test_setup_with_wrong_service_name_and_without_admin(self):
     context_obj = {
         "config": {
             api_versions.OpenStackAPIVersions.get_fullname(): {
                 "nova": {
                     "service_name": "service_name"
                 }
             }
         },
         "users": [{
             "credential": mock.MagicMock()
         }]
     }
     ctx = api_versions.OpenStackAPIVersions(context_obj)
     self.assertRaises(exceptions.ContextSetupFailure, ctx.setup)
     self.service_catalog.get_endpoints.assert_called_once_with()
     self.assertFalse(self.mock_kc.services.list.called)