Merge "Fix fuelclient error while trying to create config"

This commit is contained in:
Jenkins
2016-04-14 09:11:20 +00:00
committed by Gerrit Code Review
6 changed files with 37 additions and 25 deletions

View File

@@ -108,13 +108,18 @@ class OpenstackConfigAction(Action):
node_role = getattr(params, 'role', None)
data = OpenstackConfig.read_file(params.file)
config = OpenstackConfig.create(
configs = OpenstackConfig.create(
cluster_id=params.env,
configuration=data['configuration'],
node_ids=node_ids, node_role=node_role)
print("Openstack configuration with id {0} "
"has been uploaded from file '{1}'"
"".format(config.id, params.file))
configs = [c.data for c in configs]
self.serializer.print_to_output(
configs,
format_table(
configs,
acceptable_keys=self.acceptable_keys
)
)
@check_all('config-id')
def delete(self, params):

View File

@@ -20,6 +20,10 @@ class OpenstackConfigMixin(object):
entity_name = 'openstack-config'
columns = (
'id', 'is_active', 'config_type',
'cluster_id', 'node_id', 'node_role')
@staticmethod
def add_env_arg(parser):
parser.add_argument(
@@ -30,7 +34,7 @@ class OpenstackConfigMixin(object):
@staticmethod
def add_file_arg(parser):
parser.add_argument(
'-f', '--file', required=True,
'--file', required=True,
type=str, help='YAML file that contains openstack configuration.')
@staticmethod
@@ -69,14 +73,10 @@ class OpenstackConfigMixin(object):
)
class OpenstackConfigList(OpenstackConfigMixin, base.BaseCommand):
class OpenstackConfigList(OpenstackConfigMixin, base.BaseListCommand):
"""List all openstack configurations.
"""
columns = (
'id', 'is_active', 'config_type',
'cluster_id', 'node_id', 'node_role')
def get_parser(self, prog_name):
parser = super(OpenstackConfigList, self).get_parser(prog_name)
@@ -116,7 +116,7 @@ class OpenstackConfigDownload(OpenstackConfigMixin, base.BaseCommand):
self.app.stdout.write(msg)
class OpenstackConfigUpload(OpenstackConfigMixin, base.BaseCommand):
class OpenstackConfigUpload(OpenstackConfigMixin, base.BaseListCommand):
"""Upload new opesntack configuration from file.
"""
@@ -131,13 +131,13 @@ class OpenstackConfigUpload(OpenstackConfigMixin, base.BaseCommand):
return parser
def take_action(self, args):
config = self.client.upload(
configs = self.client.upload(
path=args.file, cluster_id=args.env,
node_ids=args.node, node_role=args.role)
msg = "OpenStack configuration with id {0} " \
"uploaded from file '{0}'\n".format(config.id, args.file)
self.app.stdout.write(msg)
data = [c.data for c in configs]
data = data_utils.get_display_data_multi(self.columns, data)
return self.columns, data
class OpenstackConfigExecute(OpenstackConfigMixin, base.BaseCommand):

View File

@@ -35,7 +35,7 @@ class OpenstackConfig(BaseObject):
def create(cls, **kwargs):
params = cls._prepare_params(kwargs)
data = cls.connection.post_request(cls.class_api_path, params)
return cls.init_with_data(data)
return [cls.init_with_data(item) for item in data]
def delete(self):
return self.connection.delete_request(

View File

@@ -62,7 +62,7 @@ class TestOpenstackConfigActions(base.UnitTestCase):
def test_config_upload(self):
m_post = self.m_request.post(
'/api/v1/openstack-config/', json=self.config)
'/api/v1/openstack-config/', json=[self.config])
m_open = mock.mock_open(read_data=yaml.safe_dump(
{'configuration': self.config['configuration']}))
with mock.patch('fuelclient.cli.serializers.open',
@@ -76,8 +76,11 @@ class TestOpenstackConfigActions(base.UnitTestCase):
self.assertEqual(req['cluster_id'], 1)
def test_config_upload_multinode(self):
configs = [utils.get_fake_openstack_config(node_id=node_id)
for node_id in [1, 2, 3]]
m_post = self.m_request.post(
'/api/v1/openstack-config/', json=self.config)
'/api/v1/openstack-config/', json=configs)
m_open = mock.mock_open(read_data=yaml.safe_dump(
{'configuration': self.config['configuration']}))

View File

@@ -78,7 +78,7 @@ class TestOpenstackConfig(test_engine.BaseCLITest):
cmd = 'openstack-config upload --env {0} ' \
'--node {1}'.format(self.CLUSTER_ID, self.NODE_ID)
self.assertRaises(SystemExit, self.exec_command, cmd)
self.assertIn('-f/--file',
self.assertIn('--file',
mocked_stderr.write.call_args_list[-1][0][0])
mocked_stderr.reset_mock()
@@ -101,7 +101,7 @@ class TestOpenstackConfig(test_engine.BaseCLITest):
def test_config_download_fail(self, mocked_stderr):
cmd = 'openstack-config download 1'
self.assertRaises(SystemExit, self.exec_command, cmd)
self.assertIn('-f/--file',
self.assertIn('--file',
mocked_stderr.write.call_args_list[-1][0][0])
def test_config_execute(self):

View File

@@ -98,7 +98,7 @@ class TestOpenstackConfigClient(test_api.BaseLibTest):
fake_config = utils.get_fake_openstack_config(
cluster_id=cluster_id)
m_post = self.m_request.post(self.uri, json=fake_config)
m_post = self.m_request.post(self.uri, json=[fake_config])
m_open = mock.mock_open(read_data=yaml.safe_dump({
'configuration': fake_config['configuration']
@@ -116,13 +116,17 @@ class TestOpenstackConfigClient(test_api.BaseLibTest):
def test_config_upload_multinode(self):
cluster_id = 1
fake_config = utils.get_fake_openstack_config(
cluster_id=cluster_id)
fake_configs = [
utils.get_fake_openstack_config(
cluster_id=cluster_id, node_id=42),
utils.get_fake_openstack_config(
cluster_id=cluster_id, node_id=44)
]
m_post = self.m_request.post(self.uri, json={'id': 42})
m_post = self.m_request.post(self.uri, json=fake_configs)
m_open = mock.mock_open(read_data=yaml.safe_dump({
'configuration': fake_config['configuration']
'configuration': fake_configs[0]['configuration']
}))
with mock.patch(
'fuelclient.cli.serializers.open', m_open, create=True), \