class TestWatcherMiddleware(unittest.TestCase): def setUp(self): self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), {}) def test_get_target_project_id_from_keystone_token_info(self): token_info = { 'token': { 'catalog': [{ 'type': 'compute', 'id': '0123456789abcdef', 'name': 'nova', 'endpoints': [{ 'url': 'https://nova.local:8774/v2.1/194dfdddb6bc43e09701035b52edb0d9', 'interface': 'public', 'region': 'region', 'id': '0123456789abcdef' }] }] } } self.watcher.service_type = 'compute' self.assertEqual( self.watcher.get_target_project_id_from_keystone_token_info( token_info), '194dfdddb6bc43e09701035b52edb0d9', "should be '194dfdddb6bc43e09701035b52edb0d9' as found in the service catalog" ) def test_fail_get_target_project_id_from_keystone_token_info(self): token_info = { 'token': { 'catalog': [{ 'type': 'compute', 'id': '0123456789abcdef', 'name': 'nova', 'endpoints': [{ 'url': 'https://nova.local:8774/v2.1', 'interface': 'public', 'region': 'region', 'id': '0123456789abcdef' }] }] } } self.watcher.service_type = 'compute' self.assertEqual( self.watcher.get_target_project_id_from_keystone_token_info( token_info), taxonomy.UNKNOWN, "should be 'unknown' as the service catalog contains no project scoped endpoint url" )
def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), { 'service_type': 'compute', 'config_file': NOVA_CONFIG_PATH }) self.is_setup = True
def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), { 'service_type': 'object-store', 'config_file': SWIFT_CONFIG_PATH, 'project_id_from_path': 'true' }) self.is_setup = True
def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), config={ 'service_type': 'image', 'config_file': GLANCE_CONFIG_PATH } ) self.is_setup = True
def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), config={ 'service_type': 'baremetal', 'config_file': IRONIC_CONFIG_PATH }) self.is_setup = True
def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), config={ 'service_type': 'key-manager', 'config_file': BARBICAN_CONFIG_PATH }) self.is_setup = True
class TestNova(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), { 'service_type': 'compute', 'config_file': NOVA_CONFIG_PATH }) self.is_setup = True def test_custom_action(self): stimuli = [ { 'request': fake.create_request( path= '/v2.1/servers/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={"addFloatingIp": { "foo": "bar" }}), 'expected': 'update/addFloatingIp' }, { 'request': fake.create_request( path= '/v2.1/servers/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={"removeSecurityGroup": { "name": "foobar" }}), 'expected': 'update/removeSecurityGroup' }, { 'request': fake.create_request(path='/v2.1/os-snapshots'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v2.1/os-snapshots', method='POST'), 'expected': 'create' }, { 'request': fake.create_request(path='/v2.1/servers'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2.1/servers/0123456789abcdef0123456789abcdef/ips'), 'expected': 'read/list' }, { 'request': fake.create_request( path= '/v2.1/servers/0123456789abcdef0123456789abcdef/ips/label' ), 'expected': 'read' }, { 'request': fake.create_request( path= '/v2.1/servers/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={"os-getConsoleOutput": { "length": 50 }}), 'expected': 'update/os-getConsoleOutput' }, { 'request': fake.create_request( path= '/v2.1/servers/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={"os-getVNCConsole": { "type": "novnc" }}), 'expected': 'update/os-getVNCConsole' }, { 'request': fake.create_request( path= '/v2.1/servers/0123456789abcdef0123456789abcdef/os-instance-actions' ), 'expected': 'read/list' }, { 'request': fake.create_request( path= '/v2.1/flavors/0123456789abcdef0123456789abcdef/os-extra_specs' ), 'expected': 'read/list' }, { 'request': fake.create_request( path= '/v2.1/flavors/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={"addTenantAccess": { "tenant": "fakeTenant" }}), 'expected': 'update/addTenantAccess' }, { 'request': fake.create_request( path= '/v2.1/images/0123456789abcdef0123456789abcdef/metadata'), 'expected': 'read/list' }, { 'request': fake.create_request( path= '/v2.1/os-aggregates/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={ "add_host": { "host": "21549b2f665945baaa7101926a00143c" } }, ), 'expected': 'update/add_host' }, ] for s in stimuli: req = s.get('request') expected = s.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual)) def test_target_type_uri(self): stimuli = [{ 'request': fake.create_request(path='/servers/myserver'), 'expected': 'service/compute/servers/server' }, { 'request': fake.create_request( path='/servers/0123456789abcdef0123456789abcdef'), 'expected': 'service/compute/servers/server' }, { 'request': fake.create_request(path='/flavors/myflavorname'), 'expected': 'service/compute/flavors/flavor' }, { 'request': fake.create_request( path='/flavors/0123456789abcdef0123456789abcdef'), 'expected': 'service/compute/flavors/flavor' }, { 'request': fake.create_request( path='/flavors/0123456789abcdef0123456789abcdef'), 'expected': 'service/compute/flavors/flavor' }, { 'request': fake.create_request( path= '/v2.1/os-aggregates/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={ "add_host": { "host": "21549b2f665945baaa7101926a00143c" } }, ), 'expected': 'service/compute/os-aggregates/os-aggregate/action' }, { 'request': fake.create_request( path='/v2.1/servers/myservername/action', method='POST', body_dict={"os-getVNCConsole": { "type": "novnc" }}), 'expected': 'service/compute/servers/server/action' }, { 'request': fake.create_request( path='/v2.1/servers/0123456789abcdef0123456789abcdef/action', method='POST', body_dict={"os-getVNCConsole": { "type": "novnc" }}), 'expected': 'service/compute/servers/server/action' }, { 'request': fake.create_request( path= '/servers/0123456789abcdef0123456789abcdef/metadata/0123456789abcdef0123456789abcdef' ), 'expected': 'service/compute/servers/server/metadata/key' }, { 'request': fake.create_request(path='/servers/myserver/metadata/foobar'), 'expected': 'service/compute/servers/server/metadata/key' }, { 'request': fake.create_request(path='/os-availability-zone/detail'), 'expected': 'service/compute/os-availability-zone/detail' }, { 'request': fake.create_request( path='/os-quota-sets/0123456789abcdef0123456789abcdef/defaults' ), 'expected': 'service/compute/os-quota-sets/os-quota-set/defaults' }, { 'request': fake.create_request(path='/os-networks/add'), 'expected': 'service/compute/os-networks/add' }, { 'request': fake.create_request( path='/os-networks/0123456789abcdef0123456789abcdef'), 'expected': 'service/compute/os-networks/os-network' }, { 'request': fake.create_request(path='/os-hypervisors/foobar/servers'), 'expected': 'service/compute/os-hypervisors/os-hypervisor/servers' }, { 'request': fake.create_request(path='/os-certificates/root'), 'expected': 'service/compute/os-certificates/root' }, { 'request': fake.create_request(path='/os-cloudpipe/configure-project'), 'expected': 'service/compute/os-cloudpipe/configure-project' }, { 'request': fake.create_request(path='/v2.1'), 'expected': 'service/compute/versions' }, { 'request': fake.create_request(path='/v2.0'), 'expected': 'service/compute/versions' }, { 'request': fake.create_request(path='/'), 'expected': 'service/compute/root' }, { 'request': fake.create_request(path=''), 'expected': 'service/compute/root' }, { 'request': fake.create_request( path='/2009-04-04/meta-data/block-device-mapping'), 'expected': 'service/compute/version/meta-data/block-device-mapping' }, { 'request': fake.create_request( path='/2009-04-04/meta-data/block-device-mapping/root'), 'expected': 'service/compute/version/meta-data/block-device-mapping/block-device-mapping' }, { 'request': fake.create_request(path='/2012-01-12/meta-data'), 'expected': 'service/compute/version/meta-data' }, { 'request': fake.create_request(path='/2012-01-12/meta-data/hostname'), 'expected': 'service/compute/version/meta-data/hostname' }, { 'request': fake.create_request(path='/2012-01-12'), 'expected': 'service/compute/version' }, { 'request': fake.create_request(path='/latest/meta-data'), 'expected': 'service/compute/version/meta-data' }] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual))
def setUp(self): self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), {})
class TestSwift(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), { 'service_type': 'object-store', 'config_file': SWIFT_CONFIG_PATH, 'project_id_from_path': 'true' }) self.is_setup = True def test_prefix(self): expected = 'service/storage/object' actual = self.watcher.strategy.target_type_uri_prefix self.assertEqual( actual, expected, "service type is object-store, hence the prefix should be '{0}' but got '{1}'" .format(expected, actual)) def test_get_target_project_uid_from_path(self): self.assertEqual( self.watcher.get_target_project_uid_from_path( '/v1/AUTH_b206a1900310484f8a9504754c84b067/containername/testfile' ), 'b206a1900310484f8a9504754c84b067', "project id in path '/v1/AUTH_b206a1900310484f8a9504754c84b067/containername/testfile' is be 'b206a1900310484f8a9504754c84b067'" ) def test_cadf_action(self): stimuli = [{ 'request': fake.create_request( path='/v1/AUTH_0123456789/containername/testfile'), 'expected': 'read' }, { 'request': fake.create_request( path='/v1/AUTH_0123456789/containername/testfile', method='HEAD'), 'expected': 'read' }, { 'request': fake.create_request( path='/v1/AUTH_0123456789/containername/testfile', method='COPY'), 'expected': 'create/copy' }, { 'request': fake.create_request( path='/v1/AUTH_0123456789/containername/testfile', method='PUT'), 'expected': 'update' }, { 'request': fake.create_request( path='/v1/AUTH_0123456789/containername/testfile', method='POST'), 'expected': 'update' }, { 'request': fake.create_request(path='/v1/AUTH_0123456789', ), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/AUTH_0123456789/containername', ), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/AUTH_0123456789', method='HEAD'), 'expected': 'read' }, { 'request': fake.create_request(path="/v1/endpoints"), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/AUTH_0123456789', method='POST'), 'expected': 'update' }] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual)) def test_target_type_uri(self): stimuli = [{ 'request': fake.create_request( path='/v1/AUTH_0123456789/containername/testfile'), 'expected': 'service/storage/object/account/container/object' }, { 'request': fake.create_request(path='/v1/AUTH_foobar/containername/testfile'), 'expected': 'service/storage/object/account/container/object' }, { 'request': fake.create_request(path='/v1/AUTH_0123456789/containername'), 'expected': 'service/storage/object/account/container' }, { 'request': fake.create_request(path='/v1/AUTH_0123456789'), 'expected': 'service/storage/object/account' }, { 'request': fake.create_request(path='/v1'), 'expected': 'service/storage/object/versions' }, { 'request': fake.create_request(path='/v1/endpoints'), 'expected': 'service/storage/object/endpoints' }, { 'request': fake.create_request(path='/info'), 'expected': 'service/storage/object/info' }, { 'request': fake.create_request(path='/'), 'expected': 'service/storage/object/root' }, { 'request': fake.create_request(path=''), 'expected': 'service/storage/object/root' }] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual)) def test_get_swift_project_id_from_path(self): stimuli = [{ 'path': '/v1/AUTH_e9141fb24eee4b3e9f25ae69cda31132', 'expected': 'e9141fb24eee4b3e9f25ae69cda31132', 'help': "path '/v1/AUTH_e9141fb24eee4b3e9f25ae69cda31132' contains the project id 'e9141fb24eee4b3e9f25ae69cda31132'" }, { 'path': '/v1/AUTH_e9141fb24eee4b3e9f25ae69cda31132/container', 'expected': 'e9141fb24eee4b3e9f25ae69cda31132', 'help': "path '/v1/AUTH_e9141fb24eee4b3e9f25ae69cda31132/container' contains the project id 'e9141fb24eee4b3e9f25ae69cda31132'" }, { 'path': '/v1/AUTH_e9141fb24eee4b3e9f25ae69cda31132/container/object', 'expected': 'e9141fb24eee4b3e9f25ae69cda31132', 'help': "path '/v1/AUTH_e9141fb24eee4b3e9f25ae69cda31132/container/object' contains the project id 'e9141fb24eee4b3e9f25ae69cda31132'" }, { 'path': 'v1/foo/bar', 'expected': 'unknown', 'help': "'v1/foo/bar' does not contain a swift project id" }] for stim in stimuli: self.assertEqual( self.watcher.strategy.get_swift_project_id_from_path( stim.get('path')), stim.get('expected'), stim.get('help')) def test_get_account_uid_and_container_name_from_request(self): stimuli = { '/v1/AUTH_0123456789/containername/testfile': ('0123456789', 'containername'), } for stim, expected in six.iteritems(stimuli): req = fake.create_request(path=stim, method='PUT') self.assertEqual( self.watcher.get_target_account_container_id_from_request(req), expected)
class TestDesignate(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), { 'service_type': 'dns', 'config_file': DESIGNATE_CONFIG_PATH } ) self.is_setup = True def test_prefix(self): self.assertEqual( self.watcher.strategy.target_type_uri_prefix, 'service/dns', "service type is dns, hence the prefix should be 'service/dns'" ) def test_cadf_action(self): stimuli = [ { 'request': fake.create_request( path='/v2/zones' ), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/zones/b206a1900310484f8a9504754c84b067/nameservers' ), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/zones/tasks/imports' ), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/zones/tasks/transfer_requests', method='PATCH' ), 'expected': 'update' }, { 'request': fake.create_request( path='/v2/reverse/floatingips' ), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/reverse/floatingips/region:b206a1900310484f8a9504754c84b067' ), 'expected': 'read' }, { 'request': fake.create_request( path='/v2/reverse/floatingips/something' ), 'expected': 'read' }, { 'request': fake.create_request( path='/v2/reverse/floatingips/something', method='POST' ), 'expected': 'create' } ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'".format(req.method, req.path, expected, actual) ) def test_target_type_uri(self): stimuli = [ { 'request': fake.create_request( path='/v2/zones'), 'expected': 'service/dns/zones' }, { 'request': fake.create_request( path='/v2/reverse/floatingips/region:b206a1900310484f8a9504754c84b067' ), 'expected': 'service/dns/reverse/floatingips/region/floatingip' }, { 'request': fake.create_request( path='/v2/quotas/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/dns/quotas/quota' }, { 'request': fake.create_request( path='/v2/blacklists/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/dns/blacklists/blacklist' }, { 'request': fake.create_request( path='/v2/zones/b206a1900310484f8a9504754c84b067/recordsets/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/dns/zones/zone/recordsets/recordset' }, { 'request': fake.create_request( path='/v2/zones/myzone/recordsets/myrecordset' ), 'expected': 'service/dns/zones/zone/recordsets/recordset' }, { 'request': fake.create_request( path='/v2/zones/tasks/imports/myzone' ), 'expected': 'service/dns/zones/tasks/imports/import' }, { 'request': fake.create_request( path='/v2/zones/zone_id/tasks/export' ), 'expected': 'service/dns/zones/zone/tasks/export' }, { 'request': fake.create_request( path='/v2/zones/tasks/exports/export' ), 'expected': 'service/dns/zones/tasks/exports/export' }, { 'request': fake.create_request( path='/v2/zones/tasks/exports/foobar/export' ), 'expected': 'service/dns/zones/tasks/exports/export/export' }, { 'request': fake.create_request( path='/v2' ), 'expected': 'service/dns/versions' }, { 'request': fake.create_request( path='/' ), 'expected': 'service/dns/root' }, { 'request': fake.create_request( path='' ), 'expected': 'service/dns/root' }, { 'request': fake.create_request( path='/v2/zones/something.com' ), 'expected': 'service/dns/zones/zone' }, ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0} {1}' should be '{2}' but got '{3}'".format(req.method, req.path, expected, actual) )
class TestManila(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), config={ 'service_type': 'share', 'config_file': MANILA_CONFIG_PATH }) self.is_setup = True def test_cadf_action(self): stimuli = [ { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/extensions'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/limits'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/shares'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/shares/detail'), 'expected': 'read/list' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/export_locations' ), 'expected': 'foobar' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/action', body_dict={ "allow_access": { "access_level": "rw", "access_type": "ip", "access_to": "0.0.0.0/0" } }), 'expected': 'update/allow_access' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/action', body_dict={"unmanage": "null"}), 'expected': 'update/unmanage' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/snapshots/b206a1900310484f8a9504754c84b067/action', body_dict={"unmanage": "null"}), 'expected': 'update/unmanage' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/action', body_dict='{ "access_list": null }'), 'expected': 'update/access_list' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/action', body_dict=u'{ "access_list": null }'), 'expected': 'update/access_list' }, ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual)) def test_target_type_uri(self): stimuli = [ { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/extensions'), 'expected': 'service/storage/share/extensions' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/limits'), 'expected': 'service/storage/share/limits' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/shares'), 'expected': 'service/storage/share/shares' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/shares/detail'), 'expected': 'service/storage/share/shares/detail' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/storage/share/shares/share' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/export_locations/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/storage/share/shares/share/export_locations/export_location' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/hasse/export_locations/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/storage/share/shares/share/export_locations/export_location' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/metadata/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/storage/share/shares/share/metadata/key' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/action', body_dict={ "allow_access": { "access_level": "rw", "access_type": "ip", "access_to": "0.0.0.0/0" } }), 'expected': 'service/storage/share/shares/share/action' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/hase/action', body_dict={ "allow_access": { "access_level": "rw", "access_type": "ip", "access_to": "0.0.0.0/0" } }), 'expected': 'service/storage/share/shares/share/action' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/shares/b206a1900310484f8a9504754c84b067/action', body_dict={"unmanage": "null"}), 'expected': 'service/storage/share/shares/share/action' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/snapshots/b206a1900310484f8a9504754c84b067/action', body_dict={"unmanage": "null"}), 'expected': 'service/storage/share/snapshots/snapshot/action' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/os-share-unmanage/b206a1900310484f8a9504754c84b067/unmanage' ), 'expected': 'service/storage/share/os-share-unmanage/share/unmanage' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/share-group-types/foobar' ), 'expected': 'service/storage/share/share-group-types/share-group-type' }, { 'request': fake.create_request( path='/v2/b206a1900310484f8a9504754c84b067/shares/manage'), 'expected': 'service/storage/share/shares/manage' }, { 'request': fake.create_request( path= '/v2/b206a1900310484f8a9504754c84b067/scheduler-stats/pools' ), 'expected': 'service/storage/share/scheduler-stats/pools' }, ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual))
class TestIronic(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), config={ 'service_type': 'baremetal', 'config_file': IRONIC_CONFIG_PATH }) self.is_setup = True def test_cadf_action(self): stimuli = [ { 'request': fake.create_request(path='/v1/nodes'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/nodes/mynode/vendor_passthru'), 'expected': 'read' }, { 'request': fake.create_request( path='/v1/nodes/mynode/vendor_passthru/methods'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/nodes/mynode/bios'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/portgroups/myportgroup/ports'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v1/drivers/mydriver/vendor_passthru/methods'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/nodes/mynode/states'), 'expected': 'read' }, { 'request': fake.create_request(path='/v1/chassis'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v1/chassis/mainchassis'), 'expected': 'read' }, ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual)) def test_target_type_uri(self): stimuli = [ { 'request': fake.create_request(path='/v1/nodes'), 'expected': 'service/compute/baremetal/nodes' }, { 'request': fake.create_request(path='/v1/nodes/mynodename'), 'expected': 'service/compute/baremetal/nodes/node' }, { 'request': fake.create_request( path='/v1/nodes/b206a1900310484f8a9504754c84b067'), 'expected': 'service/compute/baremetal/nodes/node' }, { 'request': fake.create_request(path='/v1/nodes/mynode/maintenance'), 'expected': 'service/compute/baremetal/nodes/node/maintenance' }, { 'request': fake.create_request( path= '/v1/nodes/b206a1900310484f8a9504754c84b067/maintenance'), 'expected': 'service/compute/baremetal/nodes/node/maintenance' }, { 'request': fake.create_request( path='/v1/nodes/mynodename/traits/mytraitname'), 'expected': 'service/compute/baremetal/nodes/node/traits/trait' }, { 'request': fake.create_request( path= '/v1/nodes/b206a1900310484f8a9504754c84b067/traits/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/compute/baremetal/nodes/node/traits/trait' }, { 'request': fake.create_request( path= '/v1/nodes/b206a1900310484f8a9504754c84b067/vifs/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/compute/baremetal/nodes/node/vifs/vif' }, { 'request': fake.create_request( path='/v1/drivers/gooddriver/raid/logical_disk_properties' ), 'expected': 'service/compute/baremetal/drivers/driver/raid/logical_disk_properties' }, { 'request': fake.create_request( path='/v1/nodes/hase/bios/biossettingname'), 'expected': 'service/compute/baremetal/nodes/node/bios/setting' }, { 'request': fake.create_request( path='/v1/nodes/mynnode/management/boot_device/supported'), 'expected': 'service/compute/baremetal/nodes/node/management/boot_device/supported' }, { 'request': fake.create_request(path='/v1/nodes/mynode/states/raid'), 'expected': 'service/compute/baremetal/nodes/node/states/raid' }, { 'request': fake.create_request(path='/v1/nodes/mynode/states'), 'expected': 'service/compute/baremetal/nodes/node/states' }, { 'request': fake.create_request( path='/v1/nodes/mynode/vendor_passthru/methods'), 'expected': 'service/compute/baremetal/nodes/node/vendor_passthru/methods' }, { 'request': fake.create_request(path='/v1/nodes/foobar/portgroups/detail'), 'expected': 'service/compute/baremetal/nodes/node/portgroups/detail' }, { 'request': fake.create_request(path='/v1/volume/connectors/myconnector'), 'expected': 'service/compute/baremetal/volume/connectors/connector' }, { 'request': fake.create_request( path='/v1/portgroups/someportgroup/ports/detail'), 'expected': 'service/compute/baremetal/portgroups/portgroup/ports/detail' }, { 'request': fake.create_request(path='/v1/nodes/mynode/volume/connectors'), 'expected': 'service/compute/baremetal/nodes/node/volume/connectors' }, { 'request': fake.create_request(path='/v1/nodes/mynode/volume/targets'), 'expected': 'service/compute/baremetal/nodes/node/volume/targets' }, { 'request': fake.create_request(path='/v1/chassis/mainchassis'), 'expected': 'service/compute/baremetal/chassis/chassis' }, { 'request': fake.create_request(path='/v1/chassis/detail'), 'expected': 'service/compute/baremetal/chassis/detail' }, { 'request': fake.create_request(path='/v1/heartbeat/dev-instance-00'), 'expected': 'service/compute/baremetal/heartbeat/node' }, ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0}' should be '{1}' but got '{2}'". format(req, expected, actual))
class TestGlance(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), config={ 'service_type': 'image', 'config_file': GLANCE_CONFIG_PATH } ) self.is_setup = True def test_custom_action(self): stimuli = [ { 'request': fake.create_request( path="/v3/images/b206a1900310484f8a9504754c84b067" ), 'expected': 'read' }, { 'request': fake.create_request( path="/v3/images/ubuntu16.04" ), 'expected': 'read' }, { 'request': fake.create_request( path="/v3/images" ), 'expected': 'read/list' }, { 'request': fake.create_request( path="/v2/images/myimage/actions/deactivate", method='POST' ), 'expected': 'create' }, { 'request': fake.create_request( path="/v2/images/foobuntu/members" ), 'expected': 'read/list' }, { 'request': fake.create_request( path="/v2/images/foobuntu/tags/bm", method='DELETE' ), 'expected': 'delete' }, { 'request': fake.create_request( path="/v2/schemas/images" ), 'expected': 'read/list' }, { 'request': fake.create_request( path="/v2/images/ubuntu10.10/file" ), 'expected': 'read' } ] for s in stimuli: req = s.get('request') expected = s.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'".format(req.method, req.path, expected, actual) ) def test_target_type_uri(self): stimuli = [ { 'request': fake.create_request(path='/v2/tasks'), 'expected': 'service/storage/image/tasks' }, { 'request': fake.create_request(path='/v2/schemas/tasks'), 'expected': 'service/storage/image/schemas/tasks' }, { 'request': fake.create_request(path='/v2/schemas/task'), 'expected': 'service/storage/image/schemas/task' }, { 'request': fake.create_request(path='/v2/images/ubuntu16.04/actions/deactivate'), 'expected': 'service/storage/image/images/image/actions/deactivate' }, { 'request': fake.create_request(path='/v2/images/coreos/actions/reactivate'), 'expected': 'service/storage/image/images/image/actions/reactivate' }, { 'request': fake.create_request(path='/v3/images/ubuntu16.04'), 'expected': 'service/storage/image/images/image' }, { 'request': fake.create_request(path='/v2/images/hase/members/myself'), 'expected': 'service/storage/image/images/image/members/member' }, { 'request': fake.create_request(path='/v2/images/debian/tags/virtual'), 'expected': 'service/storage/image/images/image/tags/tag' }, { 'request': fake.create_request(path='/v2/schemas/members'), 'expected': 'service/storage/image/schemas/members' }, { 'request': fake.create_request(path='/v2/schemas/member'), 'expected': 'service/storage/image/schemas/member' }, { 'request': fake.create_request(path='/v2/images/alpine/file'), 'expected': 'service/storage/image/images/image/file' }, { 'request': fake.create_request(path='/v2/images/macos/stage'), 'expected': 'service/storage/image/images/image/stage' }, { 'request': fake.create_request(path='/v2/info/import'), 'expected': 'service/storage/image/info/import' }, { 'request': fake.create_request(path='/v2/info/stores'), 'expected': 'service/storage/image/info/stores' }, { 'request': fake.create_request(path='/v2/tasks/b206a1900310484f8a9504754c84b067'), 'expected': 'service/storage/image/tasks/task' }, { 'request': fake.create_request(path='/v2/schemas/tasks'), 'expected': 'service/storage/image/schemas/tasks' } ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0} {1}' should be '{2}' but got '{3}'" .format(req.method, req.path, expected, actual) )
class TestDesignate(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware( fake.FakeApp(), { 'service_type': 'network', 'config_file': NEUTRON_CONFIG_PATH } ) self.is_setup = True def test_prefix(self): self.assertEqual( self.watcher.strategy.target_type_uri_prefix, 'service/network', "service type is network, hence the prefix should be 'service/network'" ) def test_cadf_action(self): stimuli = [ { 'request': fake.create_request(path='/v2.0/networks'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v2.0/networks/b206a1900310484f8a9504754c84b067', method='PUT' ), 'expected': 'update' }, { 'request': fake.create_request( path='/v2.0/trunks/b206a1900310484f8a9504754c84b067/get_subports' ), 'expected': 'read' }, { 'request': fake.create_request( path='/v2.0/fw/firewall_policies/b206a1900310484f8a9504754c84b067/remove_rule', method='PUT' ), 'expected': 'update' }, { 'request': fake.create_request( path='/v2.0/flavors/b206a1900310484f8a9504754c84b067/service_profiles/b206a1900310484f8a9504754c84b067', method='DELETE' ), 'expected': 'delete' }, { 'request': fake.create_request( path='/v2.0/quotas/b206a1900310484f8a9504754c84b067', method='PUT' ), 'expected': 'update' }, { 'request': fake.create_request(path='/v2.0/quotas'), 'expected': 'read/list' }, { 'request': fake.create_request(path='/v2.0/quotas/b206a1900310484f8a9504754c84b067'), 'expected': 'read' } ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'".format(req.method, req.path, expected, actual) ) def test_target_type_uri(self): stimuli = [ { 'request': fake.create_request(path='/v2.0/networks'), 'expected': 'service/network/networks' }, { 'request': fake.create_request(path='/v2.0/trunks/b206a1900310484f8a9504754c84b067/add_subports'), 'expected': 'service/network/trunks/trunk/add_subports' }, { 'request': fake.create_request( path='/v2.0/fwaas/firewall_policies/b206a1900310484f8a9504754c84b067/remove_rule' ), 'expected': 'service/network/fwaas/firewall_policies/firewall_policy/remove_rule' }, { 'request': fake.create_request( path='/v2.0/network-ip-availabilities/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/network/network-ip-availabilities/network-ip-availability' }, { 'request': fake.create_request( path='/v2.0/qos/policies/b206a1900310484f8a9504754c84b067/dscp_marking_rules/b206a1900310484f8a9504754c84b067' ), 'expected': 'service/network/qos/policies/policy/dscp_marking_rules/dscp_marking_rule' }, { 'request': fake.create_request( path='/v2.0/someresourcetype/b206a1900310484f8a9504754c84b067/tags' ), 'expected': 'service/network/resource_type/resource/tags' }, { 'request': fake.create_request( path='/v2.0/someresourcetype/b206a1900310484f8a9504754c84b067/tags/tagname' ), 'expected': 'service/network/resource_type/resource/tags/tag' }, { 'request': fake.create_request( path='/v2.0/floatingips/10.236.38.12' ), 'expected': 'service/network/floatingips/floatingip' }, { 'request': fake.create_request( path='/v2.0/security-groups/canary_sgrp_qa_de_1b' ), 'expected': 'service/network/security-groups/security-group' }, { 'request': fake.create_request( path='/v2.0/networks/private_datapath_network' ), 'expected': 'service/network/networks/network' } ] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0} {1}' should be '{2}' but got '{3}'".format(req.method, req.path, expected, actual) )
class TestBarbican(unittest.TestCase): is_setup = False def setUp(self): if self.is_setup: return self.watcher = OpenStackWatcherMiddleware(fake.FakeApp(), config={ 'service_type': 'key-manager', 'config_file': BARBICAN_CONFIG_PATH }) self.is_setup = True def test_prefix(self): expected = 'service/security/keymanager' actual = self.watcher.strategy.target_type_uri_prefix self.assertEqual( actual, expected, "service type is barbican, hence the prefix should be '{0}' but got '{1}'" .format(expected, actual)) def test_cadf_action(self): stimuli = [{ 'request': fake.create_request(path='/v1/orders'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v1/orders/0123456789abcdef0123456789abcdef'), 'expected': 'read' }, { 'request': fake.create_request(path='/v1/secrets'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v1/secrets/0123456789abcdef0123456789abcdef'), 'expected': 'read' }, { 'request': fake.create_request(path='/v1/secret-stores'), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v1/containers/0123456789abcdef0123456789abcdef/secrets' ), 'expected': 'read/list' }, { 'request': fake.create_request( path='/v1/containers/0123456789abcdef0123456789abcdef/acl'), 'expected': 'read' }, { 'request': fake.create_request(path='mycontainer/consumers'), 'expected': 'read/list' }] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_cadf_action(req) self.assertEqual( actual, expected, "cadf action for '{0} {1}' should be '{2}' but got '{3}'". format(req.method, req.path, expected, actual)) def test_target_type_uri(self): stimuli = [{ 'request': fake.create_request(path='/v1'), 'expected': 'service/security/keymanager/versions' }, { 'request': fake.create_request(path='/v1/orders'), 'expected': 'service/security/keymanager/orders' }, { 'request': fake.create_request( path='/v1/orders/0123456789abcdef0123456789abcdef'), 'expected': 'service/security/keymanager/orders/order' }, { 'request': fake.create_request(path='/v1/orders/myorder'), 'expected': 'service/security/keymanager/orders/order' }, { 'request': fake.create_request( path='/v1/secrets/0123456789abcdef0123456789abcdef/payload'), 'expected': 'service/security/keymanager/secrets/secret/payload' }, { 'request': fake.create_request( path='/v1/secrets/0123456789abcdef0123456789abcdef'), 'expected': 'service/security/keymanager/secrets/secret' }, { 'request': fake.create_request( path='/v1/secrets/0123456789abcdef0123456789abcdef/metadata'), 'expected': 'service/security/keymanager/secrets/secret/metadata' }, { 'request': fake.create_request( path= '/v1/secrets/0123456789abcdef0123456789abcdef/metadata/foobar' ), 'expected': 'service/security/keymanager/secrets/secret/metadata/key' }, { 'request': fake.create_request(path='/v1/secret-stores'), 'expected': 'service/security/keymanager/secret-stores' }, { 'request': fake.create_request(path='/v1/secret-stores/{secret_store_id}'), 'expected': 'service/security/keymanager/secret-stores/secret-store' }, { 'request': fake.create_request(path='/v1/secret-stores/preferred'), 'expected': 'service/security/keymanager/secret-stores/preferred' }, { 'request': fake.create_request(path='/v1/secret-stores/global-default'), 'expected': 'service/security/keymanager/secret-stores/global-default' }, { 'request': fake.create_request(path='/v1/containers'), 'expected': 'service/security/keymanager/containers' }, { 'request': fake.create_request( path='/v1/containers/0123456789abcdef0123456789abcdef'), 'expected': 'service/security/keymanager/containers/container' }, { 'request': fake.create_request( path='/v1/containers/0123456789abcdef0123456789abcdef/secrets' ), 'expected': 'service/security/keymanager/containers/container/secrets' }, { 'request': fake.create_request( path='/v1/secrets/0123456789abcdef0123456789abcdef/acl'), 'expected': 'service/security/keymanager/secrets/secret/acl' }, { 'request': fake.create_request( path='/v1/containers/0123456789abcdef0123456789abcdef/acl'), 'expected': 'service/security/keymanager/containers/container/acl' }, { 'request': fake.create_request(path='/v1/quotas'), 'expected': 'service/security/keymanager/quotas' }, { 'request': fake.create_request( path='/v1/project-quotas/0123456789abcdef0123456789abcdef'), 'expected': 'service/security/keymanager/project-quotas/project-quota' }, { 'request': fake.create_request( path='0123456789abcdef0123456789abcdef/consumers'), 'expected': 'service/security/keymanager/container/consumers' }, { 'request': fake.create_request(path='mycontainer/consumers'), 'expected': 'service/security/keymanager/container/consumers' }] for stim in stimuli: req = stim.get('request') expected = stim.get('expected') actual = self.watcher.determine_target_type_uri(req) self.assertEqual( actual, expected, "target_type_uri of '{0}' should be '{1}' but got '{2}'". format(req, expected, actual))