Merge "Corrected the errors in sample-show and sample-create"

This commit is contained in:
Jenkins
2015-02-15 03:24:19 +00:00
committed by Gerrit Code Review
2 changed files with 9 additions and 5 deletions

View File

@@ -379,6 +379,8 @@ class ShellSampleListCommandTest(utils.BaseTestCase):
def setUp(self):
super(ShellSampleListCommandTest, self).setUp()
self.cc = mock.Mock()
self.cc.samples = mock.Mock()
self.cc.new_samples = mock.Mock()
self.args = mock.Mock()
self.args.query = None
self.args.limit = None
@@ -469,16 +471,17 @@ class ShellSampleShowCommandTest(utils.BaseTestCase):
def setUp(self):
super(ShellSampleShowCommandTest, self).setUp()
self.cc = mock.Mock()
self.cc.new_samples = mock.Mock()
self.args = mock.Mock()
self.args.sample_id = "98b5f258-635e-11e4-8bdd-0025647390c1"
@mock.patch('sys.stdout', new=six.StringIO())
def test_sample_show(self):
sample = samples.Sample(mock.Mock(), self.SAMPLE)
self.cc.samples.get.return_value = sample
self.cc.new_samples.get.return_value = sample
ceilometer_shell.do_sample_show(self.cc, self.args)
self.cc.samples.get.assert_called_once_with(
self.cc.new_samples.get.assert_called_once_with(
"98b5f258-635e-11e4-8bdd-0025647390c1")
self.assertEqual('''\
@@ -525,6 +528,7 @@ class ShellSampleCreateCommandTest(utils.BaseTestCase):
def setUp(self):
super(ShellSampleCreateCommandTest, self).setUp()
self.cc = mock.Mock()
self.cc.samples = mock.Mock()
self.args = mock.Mock()
self.args.meter_name = self.METER
self.args.meter_type = self.METER_TYPE
@@ -536,7 +540,7 @@ class ShellSampleCreateCommandTest(utils.BaseTestCase):
def test_sample_create(self):
ret_sample = [samples.OldSample(mock.Mock(), sample)
for sample in self.SAMPLE]
self.cc.old_samples.create.return_value = ret_sample
self.cc.samples.create.return_value = ret_sample
ceilometer_shell.do_sample_create(self.cc, self.args)

View File

@@ -169,7 +169,7 @@ def _do_sample_list(cc, args):
help='ID (aka message ID) of the sample to show.')
def do_sample_show(cc, args):
'''Show an sample.'''
sample = cc.samples.get(args.sample_id)
sample = cc.new_samples.get(args.sample_id)
if sample is None:
raise exc.CommandError('Sample not found: %s' % args.sample_id)
@@ -216,7 +216,7 @@ def do_sample_create(cc, args={}):
fields[k] = json.loads(v)
else:
fields[arg_to_field_mapping.get(k, k)] = v
sample = cc.old_samples.create(**fields)
sample = cc.samples.create(**fields)
fields = ['counter_name', 'user_id', 'resource_id',
'timestamp', 'message_id', 'source', 'counter_unit',
'counter_volume', 'project_id', 'resource_metadata',