def test_create_node_with_metadata(self):
        node_name = 'node-name'
        image = self.driver.ex_get_image('debian-7')
        size = self.driver.ex_get_size('n1-standard-1')
        zone = self.driver.ex_get_zone('us-central1-a')

        # md is a list of dicts, each with 'key' and 'value' for
        # backwards compatibility
        md = [{'key': 'k0', 'value': 'v0'}, {'key': 'k1', 'value': 'v1'}]
        request, data = self.driver._create_node_req(node_name, size, image,
                                                     zone, metadata=md)
        self.assertTrue('items' in data['metadata'])
        self.assertEqual(len(data['metadata']['items']), 2)

        # md doesn't contain "items" key
        md = {'key': 'key1', 'value': 'value1'}
        request, data = self.driver._create_node_req(node_name, size, image,
                                                     zone, metadata=md)
        self.assertTrue('items' in data['metadata'])
        self.assertEqual(len(data['metadata']['items']), 1)

        # md contains "items" key
        md = {'items': [{'key': 'k0', 'value': 'v0'}]}
        request, data = self.driver._create_node_req(node_name, size, image,
                                                     zone, metadata=md)
        self.assertTrue('items' in data['metadata'])
        self.assertEqual(len(data['metadata']['items']), 1)
        self.assertEqual(data['metadata']['items'][0]['key'], 'k0')
        self.assertEqual(data['metadata']['items'][0]['value'], 'v0')
dataset/ETHPy150Open apache/libcloud/libcloud/test/compute/test_gce.py/GCENodeDriverTest.test_create_node_with_metadata/original