Exemple #1
0
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        server.return_value.registration.new_system_user_pass.return_value = {
            'system_id': '123'
        }

        config = Config('test', 'libvirt', sat_server='localhost')
        manager = Manager.fromOptions(self.logger, options, config)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(self.host_guest_report, options)
        manager.server.registration.virt_notify.assert_called_with(ANY, [
            [0, "exists", "system", {"identity": "host", "uuid": "0000000000000000"}],
            [0, "crawl_began", "system", {}],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM 9c927368-e888-43b4-9cdb-91b10431b258 from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "state": "running",
                "uuid": "9c927368e88843b49cdb91b10431b258",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM d5ffceb5-f79d-41be-a4c1-204f836e144a from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "state": "shutoff",
                "uuid": "d5ffceb5f79d41bea4c1204f836e144a",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "crawl_ended", "system", {}]
        ])
Exemple #2
0
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        options.smType = self.smType

        manager = Manager.fromOptions(self.logger, options)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(options, self.mapping, 'ABC')
        manager.server.registration.virt_notify.assert_called_with(ANY, [
            [0, "exists", "system", {"identity": "host", "uuid": "0000000000000000"}],
            [0, "crawl_began", "system", {}],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "running": "running",
                "uuid": "9c927368e88843b49cdb91b10431b258",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "running": "shutoff",
                "uuid": "d5ffceb5f79d41bea4c1204f836e144a",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "crawl_ended", "system", {}]
        ])
Exemple #3
0
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        options.smType = self.smType

        manager = Manager.fromOptions(self.logger, options)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(options, self.mapping, 'ABC')
        manager.server.registration.virt_notify.assert_called_with(ANY, [
            [
                0, 'exists', 'system', {'uuid': '0000000000000000', 'identity': 'host'}
            ], [
                0, 'crawl_began', 'system', {}
            ], [
                0, 'exists', 'domain', {
                    'state': 'running',
                    'memory_size': 0,
                    'name': 'VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670',
                    'virt_type': 'fully_virtualized',
                    'vcpus': 1,
                    'uuid': '2147647e6f064ac0982d6902c259f9d6'
                }
            ], [
                0, 'exists', 'domain', {
                    'state': 'running',
                    'memory_size': 0,
                    'name': 'VM from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670',
                    'virt_type': 'fully_virtualized',
                    'vcpus': 1,
                    'uuid': 'd5ffceb5f79d41bea4c1204f836e144a'
                }
            ], [
                0, 'crawl_ended', 'system', {}
            ]
        ])
Exemple #4
0
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        server.return_value.registration.new_system_user_pass.return_value = {
            'system_id': '123'
        }

        config = Config('test', 'libvirt', sat_server='localhost')
        manager = Manager.fromOptions(self.logger, options, config)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(self.host_guest_report, options)
        manager.server_xmlrpc.registration.virt_notify.assert_called_with(ANY, [
            [0, "exists", "system", {"identity": "host", "uuid": "0000000000000000"}],
            [0, "crawl_began", "system", {}],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM 9c927368-e888-43b4-9cdb-91b10431b258 from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "state": "running",
                "uuid": "9c927368e88843b49cdb91b10431b258",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "exists", "domain", {
                "memory_size": 0,
                "name": "VM d5ffceb5-f79d-41be-a4c1-204f836e144a from libvirt hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                "state": "shutoff",
                "uuid": "d5ffceb5f79d41bea4c1204f836e144a",
                "vcpus": 1,
                "virt_type": "fully_virtualized"
            }],
            [0, "crawl_ended", "system", {}]
        ])
Exemple #5
0
    def test_format_request_id(self):
        req = MagicMock()
        req.env = {'REQUEST_ID': '123456'}
        resp = MagicMock()

        hook_format(req, resp)

        resp.set_header.assert_called_with('X-Compute-Request-Id', '123456')
Exemple #6
0
    def test_format_request_id(self):
        req = MagicMock()
        req.env = {'REQUEST_ID': '123456'}
        resp = MagicMock()

        hook_format(req, resp)

        resp.set_header.assert_called_with('X-Compute-Request-Id', '123456')
Exemple #7
0
def test_build_base_url(url_format, pretty_urls, uri, expected):
    app = MagicMock()
    app.env = MagicMock()
    app.env.base_asset_url_format = url_format
    app.config = {'site/root': '/', 'site/pretty_urls': pretty_urls}
    assets_path = 'foo/bar-assets'
    actual = build_base_url(app, uri, assets_path)
    assert actual == expected
Exemple #8
0
 def test_upstream_admin(self):
     req = MagicMock()
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'is_admin': True}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
Exemple #9
0
 def test_upstream_xauth(self):
     req = MagicMock()
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'REMOTE_USER': '******'}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
Exemple #10
0
 def test_upstream_xauth(self):
     req = MagicMock()
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'REMOTE_USER': '******'}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
Exemple #11
0
 def test_upstream_admin(self):
     req = MagicMock()
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'is_admin': True}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
Exemple #12
0
 def test_invalid_auth(self):
     req = MagicMock()
     req.headers = {'X-AUTH-TOKEN': 'IAMBAD'}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {}
     resp = MagicMock()
     with self.assertRaises(InvalidTokenError):
         validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
Exemple #13
0
def test_build_base_url(url_format, pretty_urls, uri, expected):
    app = MagicMock()
    app.env = MagicMock()
    app.env.base_asset_url_format = url_format
    app.config = {
            'site/root': '/',
            'site/pretty_urls': pretty_urls}
    assets_path = 'foo/bar-assets'
    actual = build_base_url(app, uri, assets_path)
    assert actual == expected
Exemple #14
0
 def test_upstream_preauth(self):
     req = MagicMock()
     auth = {'user': '******'}
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'auth': auth}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertEquals(req.env.get('auth'), auth)
Exemple #15
0
 def test_upstream_preauth(self):
     req = MagicMock()
     auth = {'user': '******'}
     req.headers = {}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {'auth': auth}
     resp = MagicMock()
     validate_token(req, resp, {})
     self.assertEquals(req.env.get('auth'), auth)
Exemple #16
0
 def test_invalid_auth(self):
     req = MagicMock()
     req.headers = {'X-AUTH-TOKEN': 'IAMBAD'}
     req.method = 'GET'
     req.path = '/v2/servers'
     req.env = {}
     resp = MagicMock()
     with self.assertRaises(InvalidTokenError):
         validate_token(req, resp, {})
     self.assertIsNone(req.env.get('auth'))
Exemple #17
0
    def test_set_uuid(self):
        req = MagicMock()
        resp = MagicMock()
        req.env = {}

        hook_set_uuid(req, resp, {})

        self.assertEquals(len(req.env), 1)
        self.assertEquals(list(req.env.keys()), ['REQUEST_ID'])
        self.assertIsNotNone(req.env['REQUEST_ID'])
        self.assertTrue(req.env['REQUEST_ID'].startswith('req-'))
Exemple #18
0
    def test_set_uuid(self):
        req = MagicMock()
        resp = MagicMock()
        req.env = {}

        hook_set_uuid(req, resp, {})

        self.assertEquals(len(req.env), 1)
        self.assertEquals(list(req.env.keys()), ['REQUEST_ID'])
        self.assertIsNotNone(req.env['REQUEST_ID'])
        self.assertTrue(req.env['REQUEST_ID'].startswith('req-'))
Exemple #19
0
    def test_log_request(self, log):
        req = MagicMock()
        req.method = 'GET'
        req.path = '/'
        req.query_string = 'something=value'
        req.env = {'REQUEST_ID': '123456'}
        resp = MagicMock()
        resp.status = '200 OK'
        log_request(req, resp)

        log.info.assert_called_with('%s %s %s %s [ReqId: %s]', 'GET', '/',
                                    'something=value', '200 OK', '123456')
Exemple #20
0
 def test_unprotected(self):
     for api in ['GET:/v2', 'GET:/v2/', 'GET:/v3.0', 'GET:/v3.0/',
                 'GET:/v10.22', 'POST:/v2/tokens', 'POST:/v2.1/tokens',
                 'GET:/v2/tokens/a8Vs7bS', 'GET:/v2.0/tokens/a8Vs7bS']:
         req = MagicMock()
         req.headers = {'X-AUTH-TOKEN': None}
         req.method = api.split(':')[0]
         req.path = api.split(':')[1]
         req.env = {}
         resp = MagicMock()
         validate_token(req, resp, {})
         self.assertIsNone(req.env.get('auth'))
Exemple #21
0
    def test_get_endpoint_path(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}

        path = self.disp.get_endpoint_path(req, 'user_page')

        self.assertEquals(path, '/path/to/1234')

        path = self.disp.get_endpoint_path(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, '/path/to/1234/9876')
Exemple #22
0
    def test_get_endpoint_path(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}

        path = self.disp.get_endpoint_path(req, 'user_page')

        self.assertEquals(path, '/path/to/1234')

        path = self.disp.get_endpoint_path(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, '/path/to/1234/9876')
Exemple #23
0
    def test_admin_token(self, cfg):
        req = MagicMock()
        req.headers = {'X-AUTH-TOKEN': 'ADMIN'}
        resp = MagicMock()
        cfg.CONF = {'DEFAULT': {'admin_token': 'ADMIN'}}

        admin_token(req, resp, {})
        self.assertTrue(req.env['is_admin'])

        req.headers = {'X-AUTH-TOKEN': 'ABC'}
        req.env = {}
        admin_token(req, resp, {})
        self.assertIsNone(req.env.get('is_admin'))
Exemple #24
0
    def test_get_endpoint_url(self):
        disp = Dispatcher()
        disp.add_endpoint('user_page0', '/path0/to/{tenant_id}')
        self.app.add_dispatcher('SERVICE', disp)

        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        url = self.app.get_endpoint_url('SERVICE', req, 'user_page0')
        self.assertEqual(url, 'http://some_host/path0/to/1234')
Exemple #25
0
    def test_admin_token(self, cfg):
        req = MagicMock()
        req.headers = {'X-AUTH-TOKEN': 'ADMIN'}
        resp = MagicMock()
        cfg.CONF = {'DEFAULT': {'admin_token': 'ADMIN'}}

        admin_token(req, resp, {})
        self.assertTrue(req.env['is_admin'])

        req.headers = {'X-AUTH-TOKEN': 'ABC'}
        req.env = {}
        admin_token(req, resp, {})
        self.assertIsNone(req.env.get('is_admin'))
Exemple #26
0
    def test_get_endpoint_url(self):
        disp = Dispatcher()
        disp.add_endpoint('user_page0', '/path0/to/{tenant_id}')
        self.app.add_dispatcher('SERVICE', disp)

        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        url = self.app.get_endpoint_url('SERVICE', req, 'user_page0')
        self.assertEqual(url, 'http://some_host/path0/to/1234')
Exemple #27
0
    def test_log_request(self, log):
        req = MagicMock()
        req.method = 'GET'
        req.path = '/'
        req.query_string = 'something=value'
        req.env = {'REQUEST_ID': '123456'}
        resp = MagicMock()
        resp.status = '200 OK'
        log_request(req, resp)

        log.info.assert_called_with(
            '%s %s %s %s [ReqId: %s]',
            'GET', '/', 'something=value', '200 OK', '123456')
Exemple #28
0
 def test_unprotected(self):
     for api in [
             'GET:/v2', 'GET:/v2/', 'GET:/v3.0', 'GET:/v3.0/',
             'GET:/v10.22', 'POST:/v2/tokens', 'POST:/v2.1/tokens',
             'GET:/v2/tokens/a8Vs7bS', 'GET:/v2.0/tokens/a8Vs7bS'
     ]:
         req = MagicMock()
         req.headers = {'X-AUTH-TOKEN': None}
         req.method = api.split(':')[0]
         req.path = api.split(':')[1]
         req.env = {}
         resp = MagicMock()
         validate_token(req, resp, {})
         self.assertIsNone(req.env.get('auth'))
Exemple #29
0
    def test_get_endpoint_url(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        path = self.disp.get_endpoint_url(req, 'user_page')

        self.assertEquals(path, 'http://some_host/path/to/1234')

        path = self.disp.get_endpoint_url(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, 'http://some_host/path/to/1234/9876')
Exemple #30
0
    def test_get_endpoint_url(self):
        req = MagicMock()
        req.env = {'tenant_id': '1234'}
        req.protocol = 'http'
        req.get_header.return_value = 'some_host'
        req.app = ''

        path = self.disp.get_endpoint_url(req, 'user_page')

        self.assertEquals(path, 'http://some_host/path/to/1234')

        path = self.disp.get_endpoint_url(
            req, 'instance_detail', instance_id='9876')

        self.assertEquals(path, 'http://some_host/path/to/1234/9876')
Exemple #31
0
 def test_unprotected(self):
     for api in ['GET:/v2', 'GET:/v2/', 'GET:/v3.0', 'GET:/v3.0/',
                 'GET:/v10.22', 'POST:/v2.0/tokens', 'POST:/v2.1/tokens',
                 'GET:/v2/tokens/a8Vs7bS', 'GET:/v2.0/tokens/a8Vs7bS',
                 'POST:/v3/auth/tokens',
                 # Test listing compute API versions with and without a
                 # trailing slash on the endpoint URL.
                 'GET:/compute/',
                 'GET:/compute']:
         req = MagicMock()
         req.headers = {'X-AUTH-TOKEN': None}
         req.method = api.split(':')[0]
         req.path = api.split(':')[1]
         req.env = {}
         resp = MagicMock()
         validate_token(req, resp, {})
         self.assertIsNone(req.env.get('auth'))
Exemple #32
0
    def test_valid_auth(self, identity):
        req = MagicMock()
        req.headers = {'X-AUTH-TOKEN': 'AUTHTOK'}
        req.method = 'GET'
        req.path = '/v2/servers'
        req.env = {'tenant_id': 'public'}
        resp = MagicMock()

        def mock_validate(tok, tenant_id=None):
            self.assertEqual('AUTHTOK', tok)
            self.assertEqual('public', tenant_id)

        class MockIdDriver(object):
            def token_from_id(self, tok):
                return 'MYTOKEN'

        identity.validate_token_id = mock_validate
        identity.token_id_driver.return_value = MockIdDriver()
        validate_token(req, resp, {})
        self.assertEqual(req.env.get('auth'), 'MYTOKEN')
Exemple #33
0
    def test_valid_auth(self, identity):
        req = MagicMock()
        req.headers = {'X-AUTH-TOKEN': 'AUTHTOK'}
        req.method = 'GET'
        req.path = '/v2/servers'
        req.env = {'tenant_id': 'public'}
        resp = MagicMock()

        def mock_validate(tok, tenant_id=None):
            self.assertEqual('AUTHTOK', tok)
            self.assertEqual('public', tenant_id)

        class MockIdDriver(object):
            def token_from_id(self, tok):
                return 'MYTOKEN'

        identity.validate_token_id = mock_validate
        identity.token_id_driver.return_value = MockIdDriver()
        validate_token(req, resp, {})
        self.assertEqual(req.env.get('auth'), 'MYTOKEN')
Exemple #34
0
    def test_hypervisorCheckIn(self, server):
        options = MagicMock()
        options.smType = self.smType

        manager = Manager.fromOptions(self.logger, options)
        options.env = "ENV"
        options.owner = "OWNER"
        manager.hypervisorCheckIn(options, self.mapping, 'ABC')
        manager.server.registration.virt_notify.assert_called_with(
            ANY,
            [[
                0, "exists", "system", {
                    "identity": "host",
                    "uuid": "0000000000000000"
                }
            ], [0, "crawl_began", "system", {}],
             [
                 0, "exists", "domain", {
                     "memory_size": 0,
                     "name":
                     "VM 9c927368-e888-43b4-9cdb-91b10431b258 from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                     "running": "running",
                     "uuid": "9c927368e88843b49cdb91b10431b258",
                     "vcpus": 1,
                     "virt_type": "fully_virtualized"
                 }
             ],
             [
                 0, "exists", "domain", {
                     "memory_size": 0,
                     "name":
                     "VM d5ffceb5-f79d-41be-a4c1-204f836e144a from ABC hypervisor ad58b739-5288-4cbc-a984-bd771612d670",
                     "running": "shutoff",
                     "uuid": "d5ffceb5f79d41bea4c1204f836e144a",
                     "vcpus": 1,
                     "virt_type": "fully_virtualized"
                 }
             ], [0, "crawl_ended", "system", {}]])
 def setUp(self):
     from . import c_apacheconf
     sa = MagicMock()
     sa.env = self.tmpdir
     self.ac = c_apacheconf.c_apacheconf(sa, [])
Exemple #36
0
	def setUp(self):
		from . import c_apacheconf
		sa = MagicMock()
		sa.env = self.tmpdir
		self.ac = c_apacheconf.c_apacheconf(sa, [])