+@pytest.fixture(scope='session')
+def openmano_prefix():
+ '''Fixture that returns the prefix to be used for openmano resource names'''
+ return 'openmano'
+
+@pytest.fixture(scope='session')
+def openmano_hosts(sut_host_names):
+ '''Fixture that returns the set of host logical names to be used for openmano'''
+ return [name for name in sut_host_names if 'openmano' in name]
+
+@pytest.fixture(scope='session')
+def openmano_accounts(openmano_hosts, sut_host_addrs, cloud_accounts, openmano_prefix, logger):
+ """Fixture that returns a list of Openmano accounts. One per host, and tenant provided"""
+ accounts=[]
+
+ if not openmano_hosts:
+ return accounts
+
+ host_cycle = itertools.cycle(openmano_hosts)
+ for cloud_account in cloud_accounts:
+ if cloud_account.account_type not in ['openstack']:
+ logger.warning('Skipping creating ro datacenter for cloud account [%s] - unsupported account type [%s]', cloud_account.name, cloud_account.account_type)
+ continue
+
+ try:
+ host = next(host_cycle)
+ except StopIteration:
+ break
+
+ if cloud_account.account_type == 'openstack':
+ accounts.append({
+ 'account_name': "vim_%s" % cloud_account.name,
+ 'openmano_tenant': host,
+ 'openmano_addr': sut_host_addrs[host],
+ 'openmano_port': 9090,
+ 'datacenter': 'dc_%s' % (cloud_account.name),
+ 'vim_account': cloud_account,
+ 'vim_name': cloud_account.name,
+ 'vim_type': cloud_account.account_type,
+ 'vim_auth_url': cloud_account.openstack.auth_url,
+ 'vim_user':cloud_account.openstack.key,
+ 'vim_password':cloud_account.openstack.secret,
+ 'vim_tenant':cloud_account.openstack.tenant,
+ })
+
+ return accounts
+
+@pytest.fixture(scope='session')
+def ro_account_info(openmano_accounts):
+ ro_account_info = {}
+ for account in openmano_accounts:
+ ssh_cmd = (
+ 'ssh {openmano_addr} -q -n -o BatchMode=yes -o StrictHostKeyChecking=no -- '
+ ).format(
+ openmano_addr=account['openmano_addr']
+ )
+
+ if account['account_name'] not in ro_account_info:
+ tenant_create_cmd = (
+ '{ssh_cmd} openmano tenant-create {name}'
+ ).format(
+ ssh_cmd=ssh_cmd,
+ name=account['account_name']
+ )
+ tenant_info = subprocess.check_output(tenant_create_cmd, shell=True).decode('ascii')
+ (tenant_id, tenant_name) = tenant_info.split()
+ ro_account_info[account['account_name']] = {
+ 'tenant_id':tenant_id,
+ 'account': account,
+ 'account_type':'openmano',
+ 'host':account['openmano_addr'],
+ 'port':9090,
+ 'datacenters':[],
+ }
+ else:
+ tenant_id = ro_account_info[account['account_name']]['tenant_id']
+
+ datacenter_create_cmd = (
+ '{ssh_cmd} openmano datacenter-create --type {vim_type} {datacenter} {vim_auth_url}'
+ ).format(
+ ssh_cmd=ssh_cmd,
+ vim_type=account['vim_type'],
+ datacenter=account['datacenter'],
+ vim_auth_url=account['vim_auth_url']
+ )
+ datacenter_attach_cmd = (
+ '{ssh_cmd} OPENMANO_TENANT={tenant_id} openmano datacenter-attach {datacenter} --user={vim_user} '
+ '--password={vim_password} --vim-tenant-name={vim_tenant}'
+ ).format(
+ ssh_cmd=ssh_cmd,
+ tenant_id=tenant_id,
+ datacenter=account['datacenter'],
+ vim_user=account['vim_user'],
+ vim_password=account['vim_password'],
+ vim_tenant=account['vim_tenant']
+ )
+ subprocess.check_call(datacenter_create_cmd, shell=True)
+ subprocess.check_call(datacenter_attach_cmd, shell=True)
+
+ ro_account_info[account['account_name']]['datacenters'].append(account['datacenter'])
+ return ro_account_info
+
+
+@pytest.fixture(scope='session')
+def ro_accounts(ro_account_info):
+ '''Fixture that returns a map of RwRoAccountYang.ROAccount objects for each
+ account in ro_account_info
+ '''
+ ro_accounts = {}
+ for name, account_info in ro_account_info.items():
+ ro_accounts[name] = RwRoAccountYang.YangData_RwProject_Project_RoAccount_Account.from_dict({
+ 'name':name,
+ 'ro_account_type':account_info['account_type'],
+ 'openmano':{
+ 'host':account_info['host'],
+ 'port':account_info['port'],
+ 'tenant_id':account_info['tenant_id'],
+ }
+ })
+ return ro_accounts
+
+@pytest.fixture(scope='session')
+def ro_map(ro_account_info, ro_accounts):
+ '''Fixture that returns a map of vim name to datacenter / ro name tuples for each account in ro_account_info
+ '''
+ ro_map = {}
+ for account_name, account_info in ro_account_info.items():
+ vim_name = account_info['account']['vim_account'].name
+ datacenter_name = account_info['account']['datacenter']
+ ro_map[vim_name] = (account_name, datacenter_name)
+ return ro_map
+
+@pytest.fixture(scope='session')
+def cal(cloud_account):
+ """Fixture which returns cal interface"""
+ if cloud_account.account_type == 'openstack':
+ plugin = rw_peas.PeasPlugin('rwcal_openstack', 'RwCal-1.0')
+ elif cloud_account.account_type == 'openvim':
+ plugin = rw_peas.PeasPlugin('rwcal_openmano_vimconnector', 'RwCal-1.0')
+ elif cloud_account.account_type == 'aws':
+ plugin = rw_peas.PeasPlugin('rwcal_aws', 'RwCal-1.0')
+ elif cloud_account.account_type == 'vsphere':
+ plugin = rw_peas.PeasPlugin('rwcal-python', 'RwCal-1.0')
+
+ engine, info, extension = plugin()
+ cal = plugin.get_interface("Cloud")
+ rwloggerctx = rwlogger.RwLog.Ctx.new("Cal-Log")
+ rc = cal.init(rwloggerctx)
+ assert rc == RwTypes.RwStatus.SUCCESS
+
+ return cal
+
+@pytest.fixture(scope='session')
+def rbac_user_passwd():
+ """A common password being used for all rbac users."""
+ return 'mypasswd'
+
+@pytest.fixture(scope='session')
+def user_domain(tbac):
+ """user-domain being used in this rbac test."""
+ if tbac:
+ return 'tbacdomain'
+ return 'system'
+
+@pytest.fixture(scope='session')
+def platform_roles():
+ """Returns a tuple of platform roles"""
+ return ('rw-rbac-platform:platform-admin', 'rw-rbac-platform:platform-oper', 'rw-rbac-platform:super-admin')
+
+@pytest.fixture(scope='session')
+def user_roles():
+ """Returns a tuple of user roles"""
+ return ('rw-project:project-admin', 'rw-project:project-oper', 'rw-project-mano:catalog-oper', 'rw-project-mano:catalog-admin',
+ 'rw-project-mano:lcm-admin', 'rw-project-mano:lcm-oper', 'rw-project-mano:account-admin', 'rw-project-mano:account-oper',)
+
+@pytest.fixture(scope='session')
+def all_roles(platform_roles, user_roles):
+ """Returns a tuple of platform roles plus user roles"""
+ return platform_roles + user_roles
+
+@pytest.fixture(scope='session')
+def rw_user_proxy(mgmt_session):
+ return mgmt_session.proxy(RwUserYang)
+
+@pytest.fixture(scope='session')
+def rw_project_proxy(mgmt_session):
+ return mgmt_session.proxy(RwProjectYang)
+
+@pytest.fixture(scope='session')
+def rw_rbac_int_proxy(mgmt_session):
+ return mgmt_session.proxy(RwRbacInternalYang)
+
+@pytest.fixture(scope='session')
+def rw_ro_account_proxy(mgmt_session):
+ return mgmt_session.proxy(RwRoAccountYang)
+
+@pytest.fixture(scope='session')
+def rw_conman_proxy(mgmt_session):
+ return mgmt_session.proxy(RwConmanYang)
+
+@pytest.fixture(scope='session')
+def rbac_platform_proxy(mgmt_session):
+ return mgmt_session.proxy(RwRbacPlatformYang)
+
+@pytest.fixture(scope='session')
+def project_keyed_xpath():
+ return '/project[name={project_name}]'
+
+@pytest.fixture(scope='session')
+def user_keyed_xpath():
+ return "/user-config/user[user-name={user}][user-domain={domain}]"
+
+@pytest.fixture(scope='session')
+def platform_config_keyed_xpath():
+ return "/rbac-platform-config/user[user-name={user}][user-domain={domain}]"
+
+@pytest.fixture(scope='session')
+def fmt_vnfd_catalog_xpath():
+ """Fixture that returns vnfd-catalog keyed xpath"""
+ xpath = '/project[name={project}]/vnfd-catalog'
+ return xpath
+
+@pytest.fixture(scope='session')
+def fmt_vnfd_id_xpath():
+ """Fixture that returns vnfd id xpath"""
+ xpath = '/rw-project:project[rw-project:name={project}]/project-vnfd:vnfd-catalog/project-vnfd:vnfd[project-vnfd:id={vnfd_id}]'
+ return xpath
+
+@pytest.fixture(scope='session')
+def fmt_nsd_catalog_xpath():
+ """Fixture that returns nsd-catalog keyed xpath"""
+ xpath = '/project[name={project}]/nsd-catalog'
+ return xpath
+
+@pytest.fixture(scope='session')
+def fmt_nsd_id_xpath():
+ """Fixture that returns nsd id xpath"""
+ xpath = '/rw-project:project[rw-project:name={project}]/project-nsd:nsd-catalog/project-nsd:nsd[project-nsd:id={nsd_id}]'
+ return xpath
+
+@pytest.fixture(scope='session')
+def fmt_prefixed_cloud_xpath():
+ """Fixture that returns cloud keyed xpath"""
+ xpath = '/rw-project:project[rw-project:name={project}]/rw-cloud:cloud/rw-cloud:account[rw-cloud:name={account_name}]'
+ return xpath
+
+@pytest.fixture(scope='session')
+def fmt_cloud_xpath():
+ """Fixture that returns cloud keyed xpath without yang prefix"""
+ xpath = '/project[name={project}]/cloud/account[name={account_name}]'
+ return xpath
+
+@pytest.fixture(scope='session', autouse=True)
+def launchpad_glance_api_log():
+ log_file = os.path.join(
+ os.environ.get('HOME_RIFT', os.environ.get('RIFT_INSTALL')),
+ 'var','rift','log','glance','glance-api.log'
+ )
+ return log_file
+
+@pytest.fixture(scope='session', autouse=True)
+def _glance_api_scraper_session(request, log_manager, confd_host, launchpad_glance_api_log):
+ '''Fixture which returns an instance of rift.auto.log.FileSource to scrape
+ the glance api logs of the launchpad host
+ '''
+ scraper = rift.auto.log.FileSource(host=confd_host, path=launchpad_glance_api_log)
+ log_manager.source(source=scraper)
+ return scraper