def test_endpoint_environment_variable(self):
        fixture = fixtures.EnvironmentVariable("OS_ENDPOINT_TYPE", "public")
        self.useFixture(fixture)

        shell = openstack_shell.NeutronShell('2.0')
        parser = shell.build_option_parser('descr', '2.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)
Exemple #2
0
 def test_commands_dict_populated(self):
     # neutron.shell.COMMANDS is populated once NeutronShell is initialized.
     # To check COMMANDS during NeutronShell initialization,
     # reset COMMANDS to some dummy value before calling NeutronShell().
     self.useFixture(fixtures.MockPatchObject(openstack_shell,
                                              'COMMANDS', None))
     openstack_shell.NeutronShell('2.0')
     self.assertDictContainsSubset(
         {'net-create': network.CreateNetwork,
          'net-delete': network.DeleteNetwork,
          'net-list': network.ListNetwork,
          'net-show': network.ShowNetwork,
          'net-update': network.UpdateNetwork},
         openstack_shell.COMMANDS['2.0'])
 def test_ext_cmd_loaded(self):
     shell.NeutronShell('2.0')
     ext_cmd = {
         'cisco-hosting-device-template-list':
         hostingdevicetemplate.HostingDeviceTemplateList,
         'cisco-hosting-device-template-create':
         hostingdevicetemplate.HostingDeviceTemplateCreate,
         'cisco-hosting-device-template-update':
         hostingdevicetemplate.HostingDeviceTemplateUpdate,
         'cisco-hosting-device-template-delete':
         hostingdevicetemplate.HostingDeviceTemplateDelete,
         'cisco-hosting-device-template-show':
         hostingdevicetemplate.HostingDeviceTemplateShow
     }
     self.assertDictContainsSubset(ext_cmd, shell.COMMANDS['2.0'])
Exemple #4
0
 def test_ext_cmd_help_doc_with_extension_name(self):
     shell.NeutronShell('2.0')
     ext_cmd = {
         'cisco-hosting-device-list': hostingdevice.HostingDeviceList,
         'cisco-hosting-device-create': hostingdevice.HostingDeviceCreate,
         'cisco-hosting-device-update': hostingdevice.HostingDeviceUpdate,
         'cisco-hosting-device-delete': hostingdevice.HostingDeviceDelete,
         'cisco-hosting-device-show': hostingdevice.HostingDeviceShow,
         'cisco-hosting-device-get-config':
         hostingdevice.HostingDeviceGetConfig
     }
     self.assertDictContainsSubset(ext_cmd, shell.COMMANDS['2.0'])
     for item in ext_cmd:
         cmdcls = shell.COMMANDS['2.0'].get(item)
         self.assertTrue(cmdcls.__doc__.startswith("[hostingdevice]"))
Exemple #5
0
 def test_remote_mac_entry_cmd_loaded(self):
     neutron_shell = shell.NeutronShell('2.0')
     remote_mac_entry_cmd = {
         'gateway-device-remote-mac-entry-list':
         _remote_mac_entry.RemoteMacEntryList,
         'gateway-device-remote-mac-entry-create':
         _remote_mac_entry.RemoteMacEntryCreate,
         'gateway-device-remote-mac-entry-delete':
         _remote_mac_entry.RemoteMacEntryDelete,
         'gateway-device-remote-mac-entry-show':
         _remote_mac_entry.RemoteMacEntryShow
     }
     for cmd_name, cmd_class in remote_mac_entry_cmd.items():
         found = neutron_shell.command_manager.find_command([cmd_name])
         self.assertEqual(cmd_class, found[0])
 def shell(self, argstr):
     orig = sys.stdout
     clean_env = {}
     _old_env, os.environ = os.environ, clean_env.copy()
     try:
         sys.stdout = cStringIO.StringIO()
         _shell = openstack_shell.NeutronShell('2.0')
         _shell.run(argstr.split())
     except SystemExit:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         self.assertEqual(exc_value.code, 0)
     finally:
         out = sys.stdout.getvalue()
         sys.stdout.close()
         sys.stdout = orig
         os.environ = _old_env
     return out
Exemple #7
0
    def test_auth_cert_and_key(self):
        # emulate Keystone version discovery
        httpretty.register_uri(httpretty.GET,
                               auth.V3_URL,
                               body=auth.V3_VERSION_ENTRY)

        neutron_shell = openstack_shell.NeutronShell('2.0')
        self.addCleanup(self.mox.UnsetStubs)
        self.mox.StubOutWithMock(clientmanager.ClientManager, '__init__')
        self.mox.StubOutWithMock(neutron_shell, 'run_subcommand')
        clientmanager.ClientManager.__init__(token='',
                                             url='',
                                             auth_url=auth.V3_URL,
                                             tenant_name='test',
                                             tenant_id='tenant_id',
                                             username='******',
                                             user_id='',
                                             password='******',
                                             region_name='',
                                             api_version={'network': '2.0'},
                                             auth_strategy='keystone',
                                             service_type='network',
                                             raise_errors=False,
                                             endpoint_type='publicURL',
                                             insecure=False,
                                             ca_cert=None,
                                             retries=0,
                                             timeout=None,
                                             auth=mox.IsA(v3_auth.Password),
                                             session=mox.IsA(session.Session),
                                             log_credentials=True)
        neutron_shell.run_subcommand(['quota-list'])
        self.mox.ReplayAll()
        cmdline = ('--os-username test '
                   '--os-password test '
                   '--os-tenant-name test '
                   '--os-cert test '
                   '--os-key test '
                   '--os-auth-url %s '
                   '--os-auth-strategy keystone quota-list' % auth.V3_URL)
        neutron_shell.run(cmdline.split())
        self.mox.VerifyAll()
Exemple #8
0
    def test_ca_cert_passed_as_env_var(self):

        # emulate Keystone version discovery
        httpretty.register_uri(httpretty.GET,
                               auth.V3_URL,
                               body=auth.V3_VERSION_ENTRY)

        self.useFixture(fixtures.EnvironmentVariable('OS_CACERT', CA_CERT))

        self.mox.StubOutWithMock(ClientManager, '__init__')
        self.mox.StubOutWithMock(openstack_shell.NeutronShell, '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(),
            retries=mox.IgnoreArg(),
            raise_errors=mox.IgnoreArg(),
            log_credentials=mox.IgnoreArg(),
            timeout=mox.IgnoreArg(),
            auth=mox.IgnoreArg(),
            session=mox.IgnoreArg())
        openstack_shell.NeutronShell.interact().AndReturn(0)
        self.mox.ReplayAll()

        cmdline = ('--os-auth-url %s' % auth.V3_URL)
        openstack_shell.NeutronShell('2.0').run(cmdline.split())

        self.mox.VerifyAll()
Exemple #9
0
 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 = six.moves.cStringIO()
         sys.stderr = six.moves.cStringIO()
         _shell = openstack_shell.NeutronShell('2.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
Exemple #10
0
 def shell(self, argstr, check=False, expected_val=0):
     # expected_val is the expected return value after executing
     # the command in NeutronShell
     orig = (sys.stdout, sys.stderr)
     clean_env = {}
     _old_env, os.environ = os.environ, clean_env.copy()
     try:
         sys.stdout = StringIO()
         sys.stderr = StringIO()
         _shell = openstack_shell.NeutronShell('2.0')
         _shell.run(argstr.split())
     except SystemExit:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         self.assertEqual(expected_val, exc_value.code)
     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
Exemple #11
0
    def test_ca_cert_passed(self, mrequests):
        # emulate Keystone version discovery
        mrequests.register_uri('GET', auth.V3_URL, json=auth.V3_VERSION_ENTRY)

        self.mox.StubOutWithMock(ClientManager, '__init__')
        self.mox.StubOutWithMock(openstack_shell.NeutronShell, '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(),
            auth_plugin=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(),
            retries=mox.IgnoreArg(),
            raise_errors=mox.IgnoreArg(),
            log_credentials=mox.IgnoreArg(),
            timeout=mox.IgnoreArg(),
            auth=mox.IgnoreArg(),
            session=mox.IgnoreArg())
        openstack_shell.NeutronShell.interact().AndReturn(0)
        self.mox.ReplayAll()

        cmdline = ('--os-cacert %s --os-auth-url %s' % (CA_CERT, auth.V3_URL))

        openstack_shell.NeutronShell('2.0').run(cmdline.split())
        self.mox.VerifyAll()
 def test_ext_cmd_loaded(self):
     neutron_shell = shell.NeutronShell('2.0')
     ext_cmd = {'ip-address-list': self.IPAddressesList}
     for cmd_name, cmd_class in ext_cmd.items():
         found = neutron_shell.command_manager.find_command([cmd_name])
         self.assertEqual(cmd_class, found[0])
Exemple #13
0
 def test_build_option_parser(self):
     neutron_shell = openstack_shell.NeutronShell('2.0')
     result = neutron_shell.build_option_parser('descr', '2.0')
     self.assertEqual(True, isinstance(result, argparse.ArgumentParser))
 def test_run_unknown_command(self):
     openstack_shell.NeutronShell('2.0').run('fake')
 def _tolerant_shell(self, cmd):
     t_shell = openstack_shell.NeutronShell('2.0')
     t_shell.run(cmd.split())
Exemple #16
0
 def test_ext_cmd_loaded(self):
     shell.NeutronShell('2.0')
     ext_cmd = {'ip-address-list': self.IPAddressesList}
     self.assertDictContainsSubset(ext_cmd, shell.COMMANDS['2.0'])