def test_auth(self): #import pdb; pdb.set_trace() tacker_shell = openstack_shell.TackerShell('1.0') self.addCleanup(self.mox.UnsetStubs) self.mox.StubOutWithMock(clientmanager.ClientManager, '__init__') self.mox.StubOutWithMock(tacker_shell, 'run_subcommand') clientmanager.ClientManager.__init__(token='', url='', auth_url='http://127.0.0.1:5000/', tenant_name='test', tenant_id='tenant_id', username='******', user_id='', password='******', region_name='', api_version={'network': '1.0'}, auth_strategy='keystone', service_type='network', endpoint_type='publicURL', insecure=False, ca_cert=None, log_credentials=True) tacker_shell.run_subcommand(['device-template-list']) self.mox.ReplayAll() cmdline = ('--os-username test ' '--os-password test ' '--os-tenant-name test ' '--os-auth-url http://127.0.0.1:5000/ ' '--os-auth-strategy keystone device-template-list') tacker_shell.run(cmdline.split()) self.mox.VerifyAll()
def test_ca_cert_passed_as_env_var(self): self.useFixture(fixtures.EnvironmentVariable('OS_CACERT', CA_CERT)) self.mox.StubOutWithMock(ClientManager, '__init__') self.mox.StubOutWithMock(openstack_shell.TackerShell, 'interact') ClientManager.__init__( ca_cert=CA_CERT, # we are not really interested in other args api_version=mox.IgnoreArg(), auth_strategy=mox.IgnoreArg(), auth_url=mox.IgnoreArg(), service_type=mox.IgnoreArg(), endpoint_type=mox.IgnoreArg(), insecure=mox.IgnoreArg(), password=mox.IgnoreArg(), region_name=mox.IgnoreArg(), tenant_id=mox.IgnoreArg(), tenant_name=mox.IgnoreArg(), token=mox.IgnoreArg(), url=mox.IgnoreArg(), username=mox.IgnoreArg(), user_id=mox.IgnoreArg(), log_credentials=mox.IgnoreArg(), ) openstack_shell.TackerShell.interact().AndReturn(0) self.mox.ReplayAll() openstack_shell.TackerShell('1.0').run([]) self.mox.VerifyAll()
def test_endpoint_option(self): shell = openstack_shell.TackerShell('1.0') parser = shell.build_option_parser('descr', '1.0') # Neither $OS_ENDPOINT_TYPE nor --endpoint-type namespace = parser.parse_args([]) self.assertEqual('publicURL', namespace.endpoint_type) # --endpoint-type but not $OS_ENDPOINT_TYPE namespace = parser.parse_args(['--endpoint-type=admin']) self.assertEqual('admin', namespace.endpoint_type)
def test_main_with_unicode(self): self.mox.StubOutClassWithMocks(openstack_shell, 'TackerShell') qshell_mock = openstack_shell.TackerShell('1.0') unicode_text = u'\u7f51\u7edc' argv = ['net-list', unicode_text, unicode_text.encode('utf-8')] qshell_mock.run([u'net-list', unicode_text, unicode_text]).AndReturn(0) self.mox.ReplayAll() ret = openstack_shell.main(argv=argv) self.mox.VerifyAll() self.mox.UnsetStubs() self.assertEqual(ret, 0)
def test_endpoint_environment_variable(self): fixture = fixtures.EnvironmentVariable("OS_ENDPOINT_TYPE", "public") self.useFixture(fixture) shell = openstack_shell.TackerShell('1.0') parser = shell.build_option_parser('descr', '1.0') # $OS_ENDPOINT_TYPE but not --endpoint-type namespace = parser.parse_args([]) self.assertEqual("public", namespace.endpoint_type) # --endpoint-type and $OS_ENDPOINT_TYPE namespace = parser.parse_args(['--endpoint-type=admin']) self.assertEqual('admin', namespace.endpoint_type)
def shell(self, argstr, check=False): orig = (sys.stdout, sys.stderr) clean_env = {} _old_env, os.environ = os.environ, clean_env.copy() try: sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() _shell = openstack_shell.TackerShell('1.0') _shell.run(argstr.split()) except SystemExit: exc_type, exc_value, exc_traceback = sys.exc_info() self.assertEqual(exc_value.code, 0) finally: stdout = sys.stdout.getvalue() stderr = sys.stderr.getvalue() sys.stdout.close() sys.stderr.close() sys.stdout, sys.stderr = orig os.environ = _old_env return stdout, stderr
def _test_verify_client_manager(self, cacert): with mock.patch.object(session, 'Session'), \ mock.patch.object(clientmanager, 'ClientManager') as mock_cmgr: mock_cmgr.return_value = 0 shell = openstack_shell.TackerShell(DEFAULT_API_VERSION) shell.options = mock.Mock() auth_session = shell._get_keystone_session() shell.run(cacert) mock_cmgr.assert_called_with( api_version={'nfv-orchestration': '1.0'}, auth=auth_session.auth, auth_strategy='keystone', auth_url='', ca_cert=CA_CERT, endpoint_type='publicURL', insecure=False, log_credentials=True, password='', raise_errors=False, region_name='', retries=0, service_type='nfv-orchestration', session=auth_session, tenant_id='', tenant_name='', timeout=None, token='test_token', url='test_url', user_id='', username='')
def test_auth(self): with mock.patch.object(openstack_shell.TackerShell, 'run_subcommand'), \ mock.patch.object(session, 'Session'), \ mock.patch.object(clientmanager, 'ClientManager') as mock_cmgr: shell = openstack_shell.TackerShell(DEFAULT_API_VERSION) shell.options = mock.Mock() auth_session = shell._get_keystone_session() cmdline = ('--os-username test ' '--os-password test ' '--os-tenant-name test ' '--os-auth-url http://127.0.0.1:5000/ ' '--os-auth-strategy keystone vnfd-list') shell.authenticate_user() shell.run(cmdline.split()) mock_cmgr.assert_called_with(raise_errors=False, retries=0, timeout=None, token='', url='', auth_url='http://127.0.0.1:5000/', tenant_name='test', tenant_id='tenant_id', username='******', user_id='', password='******', region_name='', api_version={'nfv-orchestration': '1.0'}, auth_strategy='keystone', service_type='nfv-orchestration', endpoint_type='publicURL', insecure=False, ca_cert=None, log_credentials=True, session=auth_session, auth=auth_session.auth)
def test_build_option_parser(self): tacker_shell = openstack_shell.TackerShell('1.0') result = tacker_shell.build_option_parser('descr', '1.0') self.assertEqual(True, isinstance(result, argparse.ArgumentParser))
def test_build_option_parser(self): tacker_shell = openstack_shell.TackerShell(DEFAULT_API_VERSION) result = tacker_shell.build_option_parser('descr', DEFAULT_API_VERSION) self.assertIsInstance(result, argparse.ArgumentParser)