コード例 #1
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_entries_for_tenant_internal(self):
        """
        Validate that the internal API shows up in the service catalog for a
        given tenant.
        """
        iapi = make_example_internal_api(self)
        core = MimicCore(Clock(), [iapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                'some-tenant',
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 1)
        self.assertEqual(len(core._uuid_to_api_external), 0)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, "serviceType")
        self.assertEqual(catalog_entries[0].name, "serviceName")
        self.assertEqual(catalog_entries[0].tenant_id, "some-tenant")
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
コード例 #2
0
    def test_auth_accepts_tenant_name(self):
        """
        If "tenantName" is passed, the tenant specified is used instead of a
        generated tenant ID.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(json_request(
            self, root, "POST", "/identity/v2.0/tokens",
            {
                "auth": {
                    "passwordCredentials": {
                        "username": "******",
                        "password": "******"
                    },
                    "tenantName": "turtlepower"
                }
            }
        ))

        self.assertEqual(200, response.code)
        self.assertEqual("turtlepower",
                         json_body['access']['token']['tenant']['id'])
        token = json_body['access']['token']['id']
        session = core.session_for_token(token)
        self.assertEqual(token, session.token)
        self.assertEqual("turtlepower", session.tenant_id)
コード例 #3
0
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/services"
     self.eeapi_name = u"externalServiceName"
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"GET"
コード例 #4
0
ファイル: test_core.py プロジェクト: glyph/mimic
    def test_entries_for_tenant_external(self):
        """
        Validate that the external API shows up in the service catalog for a
        given tenant.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        core = MimicCore(Clock(), [eeapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry for entry in core.entries_for_tenant('some-tenant',
                                                       prefix_map, base_uri)
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 0)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, eeapi.type_key)
        self.assertEqual(catalog_entries[0].name, eeapi.name_key)
        self.assertEqual(catalog_entries[0].tenant_id, "some-tenant")
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
コード例 #5
0
    def test_response_has_auth_token(self):
        """
        The JSON response has a access.token.id key corresponding to its
        MimicCore session, and therefore access.token.tenant.id should match
        that session's tenant_id.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(json_request(
            self, root, "POST", "/identity/v2.0/tokens",
            {
                "auth": {
                    "passwordCredentials": {
                        "username": "******",
                        "password": "******"
                    }

                }
            }
        ))

        self.assertEqual(200, response.code)
        token = json_body['access']['token']['id']
        tenant_id = json_body['access']['token']['tenant']['id']
        session = core.session_for_token(token)
        self.assertEqual(token, session.token)
        self.assertEqual(tenant_id, session.tenant_id)
コード例 #6
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
 def test_get_external_api_invalid(self):
     """
     Validate retrieving a non-existent external API which should raise an
     `IndexError` exception.
     """
     core = MimicCore(Clock(), [])
     with self.assertRaises(ServiceDoesNotExist):
         core.get_external_api(self.eeapi_name)
コード例 #7
0
ファイル: test_core.py プロジェクト: tawalton/mimic
 def test_no_uuids_if_no_plugins(self):
     """
     If there are no plugins provided to :class:`MimicCore`, there are no
     uri prefixes or entries for the tenant.
     """
     core = MimicCore(Clock(), [])
     self.assertEqual(0, len(core._uuid_to_api))
     self.assertEqual([], list(core.entries_for_tenant("any_tenant", {}, "http://mimic")))
コード例 #8
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_different_username_different_token(self):
     """
     Sessions are distinct if they are requested with distinct usernames.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_username_password("a", "ignored")
     b = core.session_for_username_password("b", "ignored")
     self.assertNotEqual(a.token, b.token)
コード例 #9
0
ファイル: test_core.py プロジェクト: glyph/mimic
 def test_get_external_api_invalid(self):
     """
     Validate retrieving a non-existent external API which should raise an
     `IndexError` exception.
     """
     core = MimicCore(Clock(), [])
     with self.assertRaises(ServiceDoesNotExist):
         core.get_external_api(self.eeapi_name)
コード例 #10
0
 def test_different_username_different_token(self):
     """
     Sessions are distinct if they are requested with distinct usernames.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_username_password("a", "ignored")
     b = core.session_for_username_password("b", "ignored")
     self.assertNotEqual(a.token, b.token)
コード例 #11
0
ファイル: test_core.py プロジェクト: glyph/mimic
 def test_remove_api_invalid(self):
     """
     Validate API removal fails when it does not find the
     api name in the listing
     """
     core = MimicCore(Clock(), [])
     with self.assertRaises(ServiceDoesNotExist):
         core.remove_external_api('some-id')
コード例 #12
0
class TestIdentityMimicOSKSCatalogAdminListExternalServices(
        SynchronousTestCase, IdentityAuthMixin):
    """
    Tests for ``/identity/v2.0/services``, provided by
    :obj:`mimic.rest.idenity_api.IdentityApi`
    """
    def setUp(self):
        self.core = MimicCore(Clock(), [])
        self.root = MimicRoot(self.core).app.resource()
        self.uri = "/identity/v2.0/services"
        self.eeapi_name = u"externalServiceName"
        self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
        self.verb = b"GET"

    @ddt.data(0, 1, 10)
    def test_listing(self, api_entry_count):
        """
        GET will list the registered services.
        """
        # create the desired number of services per test parameter
        api_list = [
            ExternalApiStore(
                text_type(uuid.uuid4()),
                self.eeapi_name + text_type(uuid.uuid4()),
                'service-' + text_type(uuid.uuid4()),
            ) for ignored in range(api_entry_count)
        ]

        # add the services
        for api in api_list:
            self.core.add_api(api)

        # retrieve the listing using the REST interface
        (response, json_body) = self.successResultOf(
            json_request(self,
                         self.root,
                         self.verb,
                         self.uri,
                         headers=self.headers))

        def validate_api(api_id, api_type, api_name):
            """
            Lookup the API in the test's set of APIs  and match the values
            """
            matching_apis = [api for api in api_list if api.uuid_key == api_id]
            self.assertEqual(len(matching_apis), 1)
            [matching_api] = matching_apis
            self.assertEqual(api_id, matching_api.uuid_key)
            self.assertEqual(api_type, matching_api.type_key)
            self.assertEqual(api_name, matching_api.name_key)

        self.assertEqual(response.code, 200)
        self.assertEqual(len(json_body["OS-KSADM:services"]), len(api_list))
        # ensure all services in the response match one in the generated
        # initially generated set
        for entry in json_body["OS-KSADM:services"]:
            validate_api(entry['id'], entry['type'], entry['name'])
コード例 #13
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_no_uri_prefixes_if_no_plugins(self):
     """
     If there are no plugins provided to :class:`MimicCore`, there are no
     uri prefixes or entries for the tenant.
     """
     core = MimicCore(Clock(), [])
     self.assertEqual(0, len(core.uri_prefixes))
     self.assertEqual([], list(core.entries_for_tenant('any_tenant', {},
                                                       'http://mimic')))
コード例 #14
0
ファイル: test_core.py プロジェクト: maxlinc/mimic
 def test_no_uuids_if_no_plugins(self):
     """
     If there are no plugins provided to :class:`MimicCore`, there are no
     uri prefixes or entries for the tenant.
     """
     core = MimicCore(Clock(), [])
     self.assertEqual(0, len(core._uuid_to_api))
     self.assertEqual([], list(core.entries_for_tenant('any_tenant', {},
                                                       'http://mimic')))
コード例 #15
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_session_for_tenant_id(self):
     """
     MimicCore.session_for_tenant_id will return a session that can be
     retrieved by tenant_id.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     session = core.session_for_username_password("someuser", "testpass")
     session2 = core.session_for_tenant_id(session.tenant_id)
     self.assertIdentical(session, session2)
コード例 #16
0
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/OS-KSCATALOG/endpointTemplates"
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=True)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"GET"
コード例 #17
0
 def test_session_for_tenant_id(self):
     """
     MimicCore.session_for_tenant_id will return a session that can be
     retrieved by tenant_id.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     session = core.session_for_username_password("someuser", "testpass")
     session2 = core.session_for_tenant_id(session.tenant_id)
     self.assertIdentical(session, session2)
コード例 #18
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
 def test_remove_api_invalid(self):
     """
     Validate API removal fails when it does not find the
     api name in the listing
     """
     core = MimicCore(Clock(), [])
     with self.assertRaises(ServiceDoesNotExist):
         core.remove_external_api(
             'some-id'
         )
コード例 #19
0
ファイル: test_core.py プロジェクト: glyph/mimic
    def test_get_external_api(self):
        """
        Validate retrieving an external API.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)

        core = MimicCore(Clock(), [eeapi])
        api_from_core = core.get_external_api(eeapi.uuid_key)
        self.assertEqual(eeapi, api_from_core)
コード例 #20
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_by_username_after_token(self):
     """
     MimicCore.session_for_username_password should retrieve the same
     session that was created by MimicCore.session_for_token.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_token("testtoken")
     b = core.session_for_username_password(a.username, "testpswd")
     c = core.session_for_api_key(a.username, "testapikey")
     self.assertIdentical(a, b)
     self.assertIdentical(a, c)
コード例 #21
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_generate_username_from_tenant_id(self):
     """
     MimicCore.session_for_tenant_id will create a new session with a
     synthetic username if no such tenant ID yet exists.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     session = core.session_for_tenant_id("user_specified_tenant")
     session2 = core.session_for_username_password(session.username,
                                                   "testpass")
     self.assertIdentical(session, session2)
コード例 #22
0
 def test_generate_username_from_tenant_id(self):
     """
     MimicCore.session_for_tenant_id will create a new session with a
     synthetic username if no such tenant ID yet exists.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     session = core.session_for_tenant_id("user_specified_tenant")
     session2 = core.session_for_username_password(session.username,
                                                   "testpass")
     self.assertIdentical(session, session2)
コード例 #23
0
 def test_by_username_after_token(self):
     """
     MimicCore.session_for_username_password should retrieve the same
     session that was created by MimicCore.session_for_token.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_token("testtoken")
     b = core.session_for_username_password(a.username, "testpswd")
     c = core.session_for_api_key(a.username, "testapikey")
     self.assertIdentical(a, b)
     self.assertIdentical(a, c)
コード例 #24
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_by_token_after_username(self):
     """
     MimicCore.session_for_token should retrieve the same session that was
     created by MimicCore.session_for_username_password.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_username_password("username", "testpswd")
     b = core.session_for_token(a.token)
     self.assertIdentical(a, b)
     c = core.session_for_api_key("apiuser", "testkey")
     d = core.session_for_token(c.token)
     self.assertIdentical(c, d)
コード例 #25
0
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = ("/identity/v2.0/tenants/" + self.tenant_id +
                 "/OS-KSCATALOG/endpoints")
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=False)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"POST"
コード例 #26
0
 def setUp(self):
     self.tenant_id = 'some_tenant'
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self, name=self.eeapi_name)
     self.template_id = get_template_id(self, self.eeapi)
     self.assertIsNotNone(self.template_id)
     self.uri = ("/identity/v2.0/tenants/" + self.tenant_id +
                 "/OS-KSCATALOG/endpoints/" + self.template_id)
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"DELETE"
コード例 #27
0
ファイル: test_core.py プロジェクト: glyph/mimic
 def test_remove_api_with_endpoints(self):
     """
     Validate an API cannot be removed if it still has
     endpoints assigned to it
     """
     eeapi = make_example_external_api(self,
                                       name=self.eeapi_name,
                                       set_enabled=True)
     self.assertIsNotNone(eeapi)
     core = MimicCore(Clock(), [eeapi])
     with self.assertRaises(ServiceHasTemplates):
         core.remove_external_api(eeapi.uuid_key)
コード例 #28
0
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.eeapi_id = u"some-id"
     self.uri = "/identity/v2.0/services/" + self.eeapi_id
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(self,
                                            name=self.eeapi_name,
                                            set_enabled=True)
     self.eeapi2 = make_example_external_api(self,
                                             name=self.eeapi_name +
                                             " alternate")
     self.eeapi.uuid_key = self.eeapi_id
     self.headers = {b'X-Auth-Token': [b'ABCDEF987654321']}
     self.verb = b"DELETE"
コード例 #29
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_get_external_api(self):
        """
        Validate retrieving an external API.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi])
        api_from_core = core.get_external_api(
            eeapi.uuid_key
        )
        self.assertEqual(eeapi, api_from_core)
コード例 #30
0
ファイル: test_core.py プロジェクト: glyph/mimic
    def test_remove_api(self):
        """
        Removing an API.
        """
        eeapi = make_example_external_api(self,
                                          name=self.eeapi_name,
                                          set_enabled=True)
        self.assertIsNotNone(eeapi)

        template_ids = [ept.id_key for ept in eeapi.list_templates()]
        for template_id in template_ids:
            eeapi.remove_template(template_id)

        core = MimicCore(Clock(), [eeapi])
        core.remove_external_api(eeapi.uuid_key)
コード例 #31
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_entries_for_tenant_combined(self):
        """
        Validate that both internal and external APIs show up in the service
        catalog for a given tenant.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi, make_example_internal_api(self)])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                'some-tenant',
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 1)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 2)

        found_internal = False
        found_external = False

        for catalog_entry in catalog_entries:
            if catalog_entry.name == eeapi.name_key:
                found_external = True
                self.assertEqual(catalog_entry.type, eeapi.type_key)
                self.assertEqual(catalog_entry.name, eeapi.name_key)
                self.assertEqual(catalog_entry.tenant_id, "some-tenant")
                self.assertEqual(len(catalog_entry.endpoints), 1)

            elif catalog_entry.name == "serviceName":
                found_internal = True
                self.assertEqual(catalog_entry.type, "serviceType")
                self.assertEqual(catalog_entry.name, "serviceName")
                self.assertEqual(catalog_entry.tenant_id, "some-tenant")
                self.assertEqual(len(catalog_entry.endpoints), 1)

        self.assertTrue(found_internal)
        self.assertTrue(found_external)
コード例 #32
0
ファイル: test_auth.py プロジェクト: jirwin/mimic
    def test_session_created_for_token(self):
        """
        A session is created for the token provided
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        token = '1234567890'

        request(
            self, root, "GET",
            "/identity/v2.0/tokens/{0}/endpoints".format(token)
        )

        session = core.session_for_token(token)
        self.assertEqual(token, session.token)
コード例 #33
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_load_domain_plugin_includes_all_domain_plugins(self):
        """
        Using the :func:`MimicRoot.fromPlugin` creator for a
        :class:`MimicCore`, domain mocks implementing `class`:`IAPIDomainMock`
        are included.
        """
        self.root = FilePath(self.mktemp())
        self.root.createDirectory()
        plugin = b"""from mimic.test.dummy import ExampleDomainAPI
dummy_domain_plugin = ExampleDomainAPI()
"""
        self.root.child('fake_plugin.py').setContent(plugin)

        import mimic.plugins
        mimic.plugins.__path__.append(self.root.path)
        from mimic.plugins import fake_plugin

        def cleanup():
            sys.modules.pop("mimic.plugins.fake_plugin")
            del mimic.plugins.fake_plugin
        self.addCleanup(cleanup)

        core = MimicCore.fromPlugins(Clock())
        self.assertIn(
            fake_plugin.dummy_domain_plugin,
            core.domains
        )
コード例 #34
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
 def test_remove_api_with_endpoints(self):
     """
     Validate an API cannot be removed if it still has
     endpoints assigned to it
     """
     eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.assertIsNotNone(eeapi)
     core = MimicCore(Clock(), [eeapi])
     with self.assertRaises(ServiceHasTemplates):
         core.remove_external_api(
             eeapi.uuid_key
         )
コード例 #35
0
ファイル: test_ironic.py プロジェクト: rahulb-rackspace/mimic
 def setUp(self):
     """
     Initialize core and root
     """
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.node_details_attributes = [
         "instance_uuid", "target_power_state", "chassis_uuid",
         "properties", "uuid", "driver_info", "target_provision_state",
         "last_error", "console_enabled", "extra", "driver", "links",
         "maintenance_reason", "updated_at", "provision_updated_at",
         "maintenance", "provision_state", "reservation", "created_at",
         "power_state", "instance_info", "ports", "name",
         "driver_internal_info", "inspection_finished_at",
         "inspection_started_at", "clean_step"
     ]
     self.url = "/ironic/v1/nodes"
     self.create_request = {
         "chassis_uuid": str(uuid4()),
         "driver": "agent_ipmitool",
         "driver_info": {
             "ipmi_username": "******",
             "ipmi_address": "127.0.0.0",
             "ipmi_password": "******"
         },
         "name": "test_node",
         "properties": {
             "cpus": "1",
             "local_gb": "10",
             "memory_mb": "1024"
         }
     }
コード例 #36
0
ファイル: test_auth.py プロジェクト: ynachiket/mimic
    def test_response_has_same_roles_despite_number_of_auths(self):
        """
        The JSON response for authenticate has only one `identity:user-admin`
        role, no matter how many times the user authenticates.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        creds = {
            "auth": {
                "passwordCredentials": {
                    "username": "******",
                    "password": "******"
                }
            }
        }

        self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", creds))
        self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", creds))
        (response, json_body) = self.successResultOf(
            json_request(self, root, "POST", "/identity/v2.0/tokens", creds))

        self.assertEqual(200, response.code)
        self.assertEqual(json_body['access']['user']['roles'],
                         HARD_CODED_ROLES)
コード例 #37
0
ファイル: test_resource.py プロジェクト: ynachiket/mimic
    def test_tick(self):
        """
        ``/mimic/v1.1/tick`` (handled by :func:`MimicRoot.advance_time`)
        advances the clock associated with the service.
        """
        clock = Clock()

        def do():
            do.done = True

        do.done = False
        clock.callLater(3.5, do)
        core = MimicCore(clock, [])
        root = MimicRoot(core, clock).app.resource()
        self.assertEqual(do.done, False)
        jreq = json_request(
            self, root, "POST", "/mimic/v1.1/tick", body={"amount": 3.6}
        )
        [response, json_content] = self.successResultOf(jreq)
        self.assertEqual(response.code, 200)
        expected = {
            'advanced': 3.6,
            'now': '1970-01-01T00:00:03.600000Z',
        }
        self.assertEqual(json_content, expected)
        self.assertEqual(do.done, True)
コード例 #38
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
 def test_from_plugin_includes_all_plugins(self):
     """
     Using the :func:`MimicRoot.fromPlugin` creator for a
     :class:`MimicCore`, the nova and loadbalancer plugins are included.
     """
     core = MimicCore.fromPlugins(Clock())
     plugin_apis = set((
         glance_plugin.glance,
         heat_plugin.heat,
         loadbalancer_plugin.loadbalancer,
         loadbalancer_plugin.loadbalancer_control,
         maas_plugin.maas,
         maas_plugin.maas_control,
         nova_plugin.nova,
         nova_plugin.nova_control_api,
         queue_plugin.queue,
         rackconnect_v3_plugin.rackconnect,
         swift_plugin.swift,
         cloudfeeds_plugin.cloudfeeds,
         cloudfeeds_plugin.cloudfeeds_control,
         neutron_plugin.neutron,
         dns_plugin.dns,
         cinder_plugin.cinder
     ))
     # all plugins should be on the internal listing
     self.assertEqual(
         plugin_apis,
         set(core._uuid_to_api_internal.values()))
     # the external listing should still be empty
     self.assertEqual(
         set([]),
         set(core._uuid_to_api_external.values()))
コード例 #39
0
 def test_from_plugin_includes_all_plugins(self):
     """
     Using the :func:`MimicRoot.fromPlugin` creator for a
     :class:`MimicCore`, the nova and loadbalancer plugins are included.
     """
     core = MimicCore.fromPlugins(Clock())
     plugin_apis = set((
         glance_plugin.glance,
         loadbalancer_plugin.loadbalancer,
         loadbalancer_plugin.loadbalancer_control,
         maas_plugin.maas,
         maas_plugin.maas_control,
         nova_plugin.nova,
         nova_plugin.nova_control_api,
         queue_plugin.queue,
         rackconnect_v3_plugin.rackconnect,
         swift_plugin.swift,
         cloudfeeds_plugin.cloudfeeds,
         cloudfeeds_plugin.cloudfeeds_control,
     ))
     self.assertEqual(plugin_apis, set(core._uuid_to_api.values()))
     self.assertEqual(
         len(plugin_apis),
         len(list(core.entries_for_tenant('any_tenant', {},
                                          'http://mimic'))))
コード例 #40
0
 def setUp(self):
     """
     Initialize core and root
     """
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.url = "/valkyrie/v2.0"
コード例 #41
0
ファイル: test_core.py プロジェクト: raghav3259/mimic
 def test_from_plugin_includes_all_plugins(self):
     """
     Using the :func:`MimicRoot.fromPlugin` creator for a
     :class:`MimicCore`, the nova and loadbalancer plugins are included.
     """
     core = MimicCore.fromPlugins(Clock())
     plugin_apis = set((
         glance_plugin.glance,
         loadbalancer_plugin.loadbalancer,
         loadbalancer_plugin.loadbalancer_control,
         maas_plugin.maas,
         maas_plugin.maas_control,
         nova_plugin.nova,
         nova_plugin.nova_control_api,
         queue_plugin.queue,
         rackconnect_v3_plugin.rackconnect,
         swift_plugin.swift,
         cloudfeeds_plugin.cloudfeeds,
         cloudfeeds_plugin.cloudfeeds_control,
     ))
     self.assertEqual(
         plugin_apis,
         set(core._uuid_to_api.values()))
     self.assertEqual(
         len(plugin_apis),
         len(list(core.entries_for_tenant('any_tenant', {},
                                          'http://mimic'))))
コード例 #42
0
    def __init__(self, test_case, apis):
        """
        Initialize a mimic core and the specified :obj:`mimic.imimic.IAPIMock`s

        :param apis: A list of :obj:`mimic.imimic.IAPIMock` objects to be
            initialized
        """
        self.test_case = test_case
        self.clock = Clock()
        self.core = MimicCore(self.clock, apis)
        self.root = MimicRoot(self.core).app.resource()

        # Pass in arbitrary username and password
        self.auth = TenantAuthentication(test_case, self.root, "test1",
                                         "test1password")

        # map some attributes and methods
        self.service_catalog_json = self.auth.service_catalog_json
        self.get_service_endpoint = self.auth.get_service_endpoint

        # Tenant ID of test tenant authenticated against mimic identity
        self.tenant_id = self.auth.service_catalog_json["access"]["token"][
            "tenant"]["id"]
        service_name = apis[0].catalog_entries(self.tenant_id)[0].name
        self.uri = self.get_service_endpoint(service_name)
コード例 #43
0
ファイル: test_auth.py プロジェクト: maxlinc/mimic
    def test_get_token_and_catalog_for_token_credentials(self):
        """
        The response returned should include the credentials that were supplied
        during authentication
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "tenantId": "12345",
                        "token": {
                            "id": "iuyiuyiuy-uyiuyiuy-1987878"
                        }
                    }
                }))
        self.assertEqual(response.code, 200)
        tenant_id = json_body["access"]["token"]["tenant"]["id"]
        self.assertEqual(tenant_id, "12345")
        tenant_name = json_body["access"]["token"]["tenant"]["name"]
        self.assertEqual(tenant_name, tenant_id)
        user_name = json_body["access"]["user"]["name"]
        self.assertTrue(user_name)
コード例 #44
0
ファイル: test_auth.py プロジェクト: maxlinc/mimic
    def test_get_token_and_catalog_for_api_credentials(self):
        """
        The response returned should include the credentials that were supplied
        during authentication
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "RAX-KSKEY:apiKeyCredentials": {
                            "username": "******",
                            "apiKey": "jhgjhghg-nhghghgh-12222"
                        },
                        "tenantName": "12345"
                    }
                }))
        self.assertEqual(response.code, 200)
        tenant_id = json_body["access"]["token"]["tenant"]["id"]
        self.assertEqual(tenant_id, "12345")
        tenant_name = json_body["access"]["token"]["tenant"]["name"]
        self.assertEqual(tenant_name, tenant_id)
        user_name = json_body["access"]["user"]["name"]
        self.assertEqual(user_name, "demoauthor")
コード例 #45
0
ファイル: test_auth.py プロジェクト: maxlinc/mimic
    def test_api_service_endpoints_are_not_duplicated(self):
        """
        The service catalog should not duplicate endpoints for an entry/endpoints
        """
        regions_and_versions_list = [("ORD", "v1"), ("DFW", "v1"),
                                     ("DFW", "v2"), ("IAD", "v3")]
        core = MimicCore(
            Clock(),
            [ExampleAPI(regions_and_versions=regions_and_versions_list)])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "/identity/v2.0/tokens", {
                    "auth": {
                        "passwordCredentials": {
                            "username": "******",
                            "password": "******"
                        }
                    }
                }))
        self.assertEqual(response.code, 200)
        service_catalog = json_body["access"]["serviceCatalog"]
        self.assertEqual(len(service_catalog), 1)
        endpoints_list = service_catalog[0]["endpoints"]
        self.assertEqual(len(endpoints_list), 4)
コード例 #46
0
ファイル: test_auth.py プロジェクト: maxlinc/mimic
    def test_response_service_catalog_has_base_uri(self):
        """
        The JSON response's service catalog whose endpoints all begin with
        the same base URI as the request.
        """
        core = MimicCore(Clock(), [ExampleAPI()])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(
            json_request(
                self, root, "POST", "http://mybase/identity/v2.0/tokens", {
                    "auth": {
                        "passwordCredentials": {
                            "username": "******",
                            "password": "******"
                        }
                    }
                }))

        self.assertEqual(200, response.code)
        services = json_body['access']['serviceCatalog']
        self.assertEqual(1, len(services))

        urls = [endpoint['publicURL'] for endpoint in services[0]['endpoints']]
        self.assertEqual(1, len(urls))
        self.assertTrue(
            urls[0].startswith('http://mybase/'),
            '{0} does not start with "http://mybase"'.format(urls[0]))
コード例 #47
0
ファイル: test_core.py プロジェクト: glyph/mimic
    def test_load_domain_plugin_includes_all_domain_plugins(self):
        """
        Using the :func:`MimicRoot.fromPlugin` creator for a
        :class:`MimicCore`, domain mocks implementing `class`:`IAPIDomainMock`
        are included.
        """
        self.root = FilePath(self.mktemp())
        self.root.createDirectory()
        plugin = b"""from mimic.test.dummy import ExampleDomainAPI
dummy_domain_plugin = ExampleDomainAPI()
"""
        self.root.child('fake_plugin.py').setContent(plugin)

        import mimic.plugins
        mimic.plugins.__path__.append(self.root.path)
        from mimic.plugins import fake_plugin

        def cleanup():
            sys.modules.pop("mimic.plugins.fake_plugin")
            del mimic.plugins.fake_plugin

        self.addCleanup(cleanup)

        core = MimicCore.fromPlugins(Clock())
        self.assertIn(fake_plugin.dummy_domain_plugin, core.domains)
コード例 #48
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_entries_for_tenant_external_with_tenantid_replacement(self):
        """
        Validate that the external API shows up in the service catalog for a
        given tenant and the tenant id is in the URL.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        tenant_id = 'some-tenant-other'

        ept_internal_url = "http://internal.url/v1/" + tenant_id
        ept_public_url = "http://public.url/v1/" + tenant_id
        for ept in eeapi.endpoint_templates.values():
            ept.internal_url = "http://internal.url/v1/%tenant_id%"
            ept.public_url = "http://public.url/v1/%tenant_id%"

        core = MimicCore(Clock(), [eeapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                tenant_id,
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 0)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, eeapi.type_key)
        self.assertEqual(catalog_entries[0].name, eeapi.name_key)
        self.assertEqual(catalog_entries[0].tenant_id, tenant_id)
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
        self.assertEqual(
            catalog_entries[0].endpoints[0].internal_url,
            ept_internal_url
        )
        self.assertEqual(
            catalog_entries[0].endpoints[0].complete_url,
            ept_public_url
        )
コード例 #49
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_username_password_new(self):
     """
     MimicCore.session_for_username_password creates a new session (if no
     such session exists for the given username).
     """
     clock = Clock()
     core = MimicCore(clock, [])
     clock.advance(4321)
     session = core.session_for_username_password("example_user",
                                                  "password")
     self.assertEqual(session.username, "example_user")
     self.assertEqual(session.expires,
                      datetime.utcfromtimestamp(4321 + 86400))
     self.assertIsInstance(session.tenant_id, six.text_type)
     self.assertIsInstance(session.token, six.text_type)
     self.assertNotEqual(session.username, session.token)
     self.assertNotEqual(session.token, session.tenant_id)
コード例 #50
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_get_external_apis(self):
        """
        Validate retrieving the list of external APIs
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [])
        self.assertEqual(len(core.get_external_apis()), 0)

        core.add_api(eeapi)
        api_list = core.get_external_apis()
        self.assertEqual(len(api_list), 1)
        self.assertEqual(list(api_list), [eeapi.uuid_key])
コード例 #51
0
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/services"
     self.eeapi_name = u"externalServiceName"
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"GET"
コード例 #52
0
ファイル: test_core.py プロジェクト: rackerlabs/mimic
    def test_remove_api(self):
        """
        Removing an API.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )
        self.assertIsNotNone(eeapi)

        template_ids = [ept.id_key for ept in eeapi.list_templates()]
        for template_id in template_ids:
            eeapi.remove_template(template_id)

        core = MimicCore(Clock(), [eeapi])
        core.remove_external_api(
            eeapi.uuid_key
        )
コード例 #53
0
ファイル: tap.py プロジェクト: jirwin/mimic
def makeService(config):
    """
    Set up the otter-api service.
    """
    s = MultiService()
    core = MimicCore.fromPlugins(Clock())
    root = MimicRoot(core)
    site = Site(root.app.resource())
    site.displayTracebacks = False
    service(config['listen'], site).setServiceParent(s)
    return s
コード例 #54
0
ファイル: test_core.py プロジェクト: jirwin/mimic
 def test_impersonation(self):
     """
     MimicCore.session_for_impersonation will return a session that can be
     retrieved by token_id but not username.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     A_LITTLE = 1234
     clock.advance(A_LITTLE)
     A_LOT = 65432
     a = core.session_for_impersonation("pretender", A_LOT)
     a_prime = core.session_for_impersonation("pretender", A_LOT)
     self.assertIdentical(a, a_prime)
     b = core.session_for_token(a.token)
     self.assertEqual(
         a.expires, datetime.utcfromtimestamp(A_LITTLE + A_LOT))
     self.assertIdentical(a, b)
     c = core.session_for_username_password("pretender", "not a password")
     self.assertNotIdentical(a, c)
     self.assertEqual(a.username, c.username)
     self.assertEqual(a.tenant_id, c.tenant_id)
コード例 #55
0
ファイル: test_core.py プロジェクト: kivattik/mimic
 def test_from_plugin_includes_all_plugins(self):
     """
     Using the :func:`MimicRoot.fromPlugin` creator for a
     :class:`MimicCore`, the nova and loadbalancer plugins are included.
     """
     core = MimicCore.fromPlugins(Clock())
     self.assertEqual(
         set((nova_plugin.nova, loadbalancer_plugin.loadbalancer)),
         set(core._uuid_to_api.values()))
     self.assertEqual(
         2, len(list(core.entries_for_tenant('any_tenant', {},
                                             'http://mimic'))))
コード例 #56
0
 def setUp(self):
     self.core = MimicCore(Clock(), [])
     self.root = MimicRoot(self.core).app.resource()
     self.uri = "/identity/v2.0/OS-KSCATALOG/endpointTemplates"
     self.eeapi_name = u"externalServiceName"
     self.eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.headers = {
         b'X-Auth-Token': [b'ABCDEF987654321']
     }
     self.verb = b"GET"
コード例 #57
0
ファイル: tap.py プロジェクト: BenjamenMeyer/mimic
def makeService(config):
    """
    Set up the otter-api service.
    """
    s = MultiService()
    if config['realtime']:
        from twisted.internet import reactor as clock
    else:
        clock = Clock()
    core = MimicCore.fromPlugins(clock)
    root = MimicRoot(core, clock)
    site = get_site(root.app.resource(), logging=bool(config['verbose']))
    service(config['listen'], site).setServiceParent(s)
    return s
コード例 #58
0
ファイル: tap.py プロジェクト: amitgandhinz/mimic
def makeService(config):
    """
    Set up the otter-api service.
    """
    s = MultiService()
    if config['realtime']:
        from twisted.internet import reactor as clock
    else:
        clock = Clock()
    core = MimicCore.fromPlugins(clock)
    root = MimicRoot(core, clock)
    site = Site(root.app.resource())
    site.displayTracebacks = False
    service(config['listen'], site).setServiceParent(s)
    return s