Merge "Add ceilometerclient support for api-no-pipeline"
This commit is contained in:
		@@ -54,7 +54,9 @@ GET_SAMPLE = {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
METER_URL = '/v2/meters/instance'
 | 
			
		||||
METER_URL_DIRECT = '/v2/meters/instance?direct=True'
 | 
			
		||||
SECOND_METER_URL = '/v2/meters/image'
 | 
			
		||||
SECOND_METER_URL_DIRECT = '/v2/meters/image?direct=True'
 | 
			
		||||
SAMPLE_URL = '/v2/samples'
 | 
			
		||||
QUERIES = ('q.field=resource_id&q.field=source&q.op=&q.op='
 | 
			
		||||
           '&q.type=&q.type=&q.value=foo&q.value=bar')
 | 
			
		||||
@@ -71,12 +73,24 @@ OLD_SAMPLE_FIXTURES = {
 | 
			
		||||
            [CREATE_SAMPLE],
 | 
			
		||||
        ),
 | 
			
		||||
    },
 | 
			
		||||
    METER_URL_DIRECT: {
 | 
			
		||||
        'POST': (
 | 
			
		||||
            {},
 | 
			
		||||
            [CREATE_SAMPLE],
 | 
			
		||||
        )
 | 
			
		||||
    },
 | 
			
		||||
    SECOND_METER_URL: {
 | 
			
		||||
        'POST': (
 | 
			
		||||
            {},
 | 
			
		||||
            [CREATE_LIST_SAMPLE] * 10,
 | 
			
		||||
        ),
 | 
			
		||||
    },
 | 
			
		||||
    SECOND_METER_URL_DIRECT: {
 | 
			
		||||
        'POST': (
 | 
			
		||||
            {},
 | 
			
		||||
            [CREATE_LIST_SAMPLE] * 10,
 | 
			
		||||
        )
 | 
			
		||||
    },
 | 
			
		||||
    '%s?%s' % (METER_URL, QUERIES): {
 | 
			
		||||
        'GET': (
 | 
			
		||||
            {},
 | 
			
		||||
@@ -156,6 +170,14 @@ class OldSampleManagerTest(utils.BaseTestCase):
 | 
			
		||||
        self.http_client.assert_called(*expect, body=[CREATE_SAMPLE])
 | 
			
		||||
        self.assertIsNotNone(sample)
 | 
			
		||||
 | 
			
		||||
    def test_create_directly(self):
 | 
			
		||||
        sample = self.mgr.create(direct=True, **CREATE_SAMPLE)
 | 
			
		||||
        expect = [
 | 
			
		||||
            'POST', '/v2/meters/instance?direct=True'
 | 
			
		||||
        ]
 | 
			
		||||
        self.http_client.assert_called(*expect, body=[CREATE_SAMPLE])
 | 
			
		||||
        self.assertIsNotNone(sample)
 | 
			
		||||
 | 
			
		||||
    def test_create_list(self):
 | 
			
		||||
        test_samples = [CREATE_LIST_SAMPLE] * 10
 | 
			
		||||
        samples = self.mgr.create_list(test_samples)
 | 
			
		||||
@@ -165,6 +187,15 @@ class OldSampleManagerTest(utils.BaseTestCase):
 | 
			
		||||
        self.http_client.assert_called(*expect, body=test_samples)
 | 
			
		||||
        self.assertEqual(10, len(samples))
 | 
			
		||||
 | 
			
		||||
    def test_create_list_directly(self):
 | 
			
		||||
        test_samples = [CREATE_LIST_SAMPLE] * 10
 | 
			
		||||
        samples = self.mgr.create_list(test_samples, direct=True)
 | 
			
		||||
        expect = [
 | 
			
		||||
            'POST', '/v2/meters/image?direct=True'
 | 
			
		||||
        ]
 | 
			
		||||
        self.http_client.assert_called(*expect, body=test_samples)
 | 
			
		||||
        self.assertEqual(10, len(samples))
 | 
			
		||||
 | 
			
		||||
    def test_limit(self):
 | 
			
		||||
        samples = list(self.mgr.list(meter_name='instance', limit=1))
 | 
			
		||||
        expect = ['GET', '/v2/meters/instance?limit=1']
 | 
			
		||||
 
 | 
			
		||||
@@ -619,7 +619,8 @@ class ShellSampleCreateListCommandTest(utils.BaseTestCase):
 | 
			
		||||
                                         sample) for sample in self.samples]
 | 
			
		||||
        self.cc.samples.create_list.return_value = ret_samples
 | 
			
		||||
        ceilometer_shell.do_sample_create_list(self.cc, self.args)
 | 
			
		||||
        self.cc.samples.create_list.assert_called_with(self.samples)
 | 
			
		||||
        self.cc.samples.create_list.assert_called_with(self.samples,
 | 
			
		||||
                                                       direct=mock.ANY)
 | 
			
		||||
        self.assertEqual('''\
 | 
			
		||||
+--------------------------------------+-------+------------+--------+-------\
 | 
			
		||||
+----------------------------+
 | 
			
		||||
 
 | 
			
		||||
@@ -49,15 +49,18 @@ class OldSampleManager(base.Manager):
 | 
			
		||||
        return self._list(options.build_url(path, q, params))
 | 
			
		||||
 | 
			
		||||
    def create(self, **kwargs):
 | 
			
		||||
        direct = kwargs.pop('direct', False)
 | 
			
		||||
        new = dict((key, value) for (key, value) in kwargs.items()
 | 
			
		||||
                   if key in CREATION_ATTRIBUTES)
 | 
			
		||||
        url = self._path(counter_name=kwargs['counter_name'])
 | 
			
		||||
        url = self._path(counter_name=kwargs['counter_name'])+(
 | 
			
		||||
            '?direct=%s' % (str(direct)) if direct else '')
 | 
			
		||||
        body = self.api.post(url, json=[new]).json()
 | 
			
		||||
        if body:
 | 
			
		||||
            return [OldSample(self, b) for b in body]
 | 
			
		||||
 | 
			
		||||
    def create_list(self, sample_list=None, **kwargs):
 | 
			
		||||
        sample_dict = {}
 | 
			
		||||
        direct = kwargs.pop('direct', False)
 | 
			
		||||
 | 
			
		||||
        for sample_body in sample_list:
 | 
			
		||||
            sample = dict((key, value) for (key, value) in sample_body.items()
 | 
			
		||||
@@ -69,7 +72,8 @@ class OldSampleManager(base.Manager):
 | 
			
		||||
        sample_return_list = []
 | 
			
		||||
 | 
			
		||||
        for (counter_name, sample_body) in sample_dict.items():
 | 
			
		||||
            url = self._path(counter_name=counter_name)
 | 
			
		||||
            url = self._path(counter_name=counter_name)+(
 | 
			
		||||
                '?direct=%s' % (str(direct)) if direct else '')
 | 
			
		||||
            body = self.api.post(url, json=sample_body).json()
 | 
			
		||||
 | 
			
		||||
            if body:
 | 
			
		||||
 
 | 
			
		||||
@@ -216,6 +216,8 @@ def _restore_shadowed_arg(shadowed, observed):
 | 
			
		||||
                'key-value pairs e.g. {"key":"value"}.')
 | 
			
		||||
@utils.arg('--timestamp', metavar='<TIMESTAMP>',
 | 
			
		||||
           help='The sample timestamp.')
 | 
			
		||||
@utils.arg('--direct', metavar='<DIRECT>', default=False,
 | 
			
		||||
           help='Post sample to storage directly.')
 | 
			
		||||
@_restore_shadowed_arg('project_id', 'sample_project_id')
 | 
			
		||||
@_restore_shadowed_arg('user_id', 'sample_user_id')
 | 
			
		||||
def do_sample_create(cc, args={}):
 | 
			
		||||
@@ -265,10 +267,12 @@ def do_meter_list(cc, args={}):
 | 
			
		||||
 | 
			
		||||
@utils.arg('samples_list', metavar='<SAMPLES_LIST>', action=NotEmptyAction,
 | 
			
		||||
           help='Json array with samples to create.')
 | 
			
		||||
@utils.arg('--direct', metavar='<DIRECT>', default=False,
 | 
			
		||||
           help='Post samples to storage directly.')
 | 
			
		||||
def do_sample_create_list(cc, args={}):
 | 
			
		||||
    """Create a sample list."""
 | 
			
		||||
    sample_list_array = json.loads(args.samples_list)
 | 
			
		||||
    samples = cc.samples.create_list(sample_list_array)
 | 
			
		||||
    samples = cc.samples.create_list(sample_list_array, direct=args.direct)
 | 
			
		||||
    field_labels = ['Resource ID', 'Name', 'Type', 'Volume', 'Unit',
 | 
			
		||||
                    'Timestamp']
 | 
			
		||||
    fields = ['resource_id', 'counter_name', 'counter_type',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user