Parse the provided container environment

Users should be able to provide environment in the following way:
$ zun container-create --environment key1=value1 \
    --environment key2=value2 \
    ...

In addition, most of the unit tests were not running due to an
incorrect path in testr.conf. This commit fixed it.

Change-Id: I90ca3cd0732616eae180abf0c8daf98abf01bd77
This commit is contained in:
Hongbin Lu 2016-09-16 13:09:45 -05:00
parent 75ffef6d72
commit bcd33fe32f
5 changed files with 22 additions and 11 deletions

View File

@ -2,6 +2,6 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./zunclient/tests/unit} $LISTOPT $IDOPTION ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE test_id_option=--load-list $IDFILE
test_list_option=--list test_list_option=--list

View File

@ -3,3 +3,6 @@
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
pbr>=1.6 # Apache-2.0 pbr>=1.6 # Apache-2.0
oslo.i18n>=2.1.0 # Apache-2.0
oslo.utils>=3.16.0 # Apache-2.0
PrettyTable>=0.7.1,<0.8 # BSD

View File

@ -88,7 +88,7 @@ class ShellTest(utils.TestCase):
def test_help(self): def test_help(self):
required = [ required = [
'.*?^usage: ', '.*?^usage: ',
'.*?^\s+container-stop\s+Stop specified container.', '.*?^\s+stop\s+Stop specified container.',
'.*?^See "zun help COMMAND" for help on a specific command', '.*?^See "zun help COMMAND" for help on a specific command',
] ]
stdout, stderr = self.shell('help') stdout, stderr = self.shell('help')
@ -98,11 +98,11 @@ class ShellTest(utils.TestCase):
def test_help_on_subcommand(self): def test_help_on_subcommand(self):
required = [ required = [
'.*?^usage: zun container-create', '.*?^usage: zun create',
'.*?^Create a container.', '.*?^Create a container.',
'.*?^Optional arguments:', '.*?^Optional arguments:',
] ]
stdout, stderr = self.shell('help container-create') stdout, stderr = self.shell('help create')
for r in required: for r in required:
self.assertThat((stdout + stderr), self.assertThat((stdout + stderr),
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
@ -110,7 +110,7 @@ class ShellTest(utils.TestCase):
def test_help_no_options(self): def test_help_no_options(self):
required = [ required = [
'.*?^usage: ', '.*?^usage: ',
'.*?^\s+container-stop\s+Stop specified container.', '.*?^\s+stop\s+Stop specified container.',
'.*?^See "zun help COMMAND" for help on a specific command', '.*?^See "zun help COMMAND" for help on a specific command',
] ]
stdout, stderr = self.shell('') stdout, stderr = self.shell('')
@ -124,8 +124,8 @@ class ShellTest(utils.TestCase):
required = [ required = [
'.*--json', '.*--json',
'.*help', '.*help',
'.*container-show', '.*show',
'.*--container'] '.*--name']
for r in required: for r in required:
self.assertThat((stdout + stderr), self.assertThat((stdout + stderr),
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
@ -195,7 +195,14 @@ class ShellTest(utils.TestCase):
_, client_kwargs = mock_client.call_args_list[0] _, client_kwargs = mock_client.call_args_list[0]
self.assertEqual('container', client_kwargs['service_type']) self.assertEqual('container', client_kwargs['service_type'])
@mock.patch('zunclient.v1.services_shell.do_services_list') @mock.patch('zunclient.v1.client.Client')
def test_container_format_env(self, mock_client):
self.make_env()
self.shell('create --environment key=value --image test')
_, create_args = mock_client.return_value.containers.create.call_args
self.assertEqual({'key': 'value'}, create_args['environment'])
@mock.patch('zunclient.v1.services_shell.do_service_list')
@mock.patch('zunclient.v1.client.ksa_session') @mock.patch('zunclient.v1.client.ksa_session')
def test_insecure(self, mock_session, mock_services_list): def test_insecure(self, mock_session, mock_services_list):
self.make_env() self.make_env()

View File

@ -86,7 +86,7 @@ class ServiceManagerTest(testtools.TestCase):
def setUp(self): def setUp(self):
super(ServiceManagerTest, self).setUp() super(ServiceManagerTest, self).setUp()
self.api = utils.FakeAPI(fake_responses) self.api = utils.FakeAPI(fake_responses)
self.mgr = services.MServiceManager(self.api) self.mgr = services.ServiceManager(self.api)
def test_service_list(self): def test_service_list(self):
services = self.mgr.list() services = self.mgr.list()

View File

@ -37,7 +37,8 @@ def _show_container(container):
help='The container memory size (format: <number><optional unit>, ' help='The container memory size (format: <number><optional unit>, '
'where unit = b, k, m or g)') 'where unit = b, k, m or g)')
@utils.arg('-e', '--environment', @utils.arg('-e', '--environment',
metavar='<environment>', metavar='<KEY=VALUE>',
action='append', default=[],
help='The environment variabled') help='The environment variabled')
def do_create(cs, args): def do_create(cs, args):
"""Create a container.""" """Create a container."""
@ -46,7 +47,7 @@ def do_create(cs, args):
opts['image'] = args.image opts['image'] = args.image
opts['command'] = args.command opts['command'] = args.command
opts['memory'] = args.memory opts['memory'] = args.memory
opts['environment'] = args.environment opts['environment'] = zun_utils.format_labels(args.environment)
_show_container(cs.containers.create(**opts)) _show_container(cs.containers.create(**opts))