sapan-kona | 17d7f06 | 2011-12-22 17:35:00 +0530 | [diff] [blame] | 1 | from nose.plugins.attrib import attr |
Daryl Walleck | ed8bef3 | 2011-12-05 23:02:08 -0600 | [diff] [blame] | 2 | from tempest import openstack |
| 3 | from tempest.common.utils.data_utils import rand_name |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 4 | import unittest2 as unittest |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 5 | |
| 6 | |
| 7 | class ServerMetadataTest(unittest.TestCase): |
| 8 | |
| 9 | @classmethod |
| 10 | def setUpClass(cls): |
| 11 | cls.os = openstack.Manager() |
| 12 | cls.client = cls.os.servers_client |
Jay Pipes | 7f75763 | 2011-12-02 15:53:32 -0500 | [diff] [blame] | 13 | cls.config = cls.os.config |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 14 | cls.image_ref = cls.config.env.image_ref |
| 15 | cls.flavor_ref = cls.config.env.flavor_ref |
| 16 | |
| 17 | #Create a server to be used for all read only tests |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 18 | name = rand_name('server') |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 19 | resp, server = cls.client.create_server(name, cls.image_ref, |
| 20 | cls.flavor_ref, meta={}) |
| 21 | cls.server_id = server['id'] |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 22 | |
| 23 | #Wait for the server to become active |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 24 | cls.client.wait_for_server_status(cls.server_id, 'ACTIVE') |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 25 | |
| 26 | @classmethod |
| 27 | def tearDownClass(cls): |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 28 | cls.client.delete_server(cls.server_id) |
| 29 | |
| 30 | def setUp(self): |
| 31 | meta = {'key1': 'value1', 'key2': 'value2'} |
| 32 | resp, _ = self.client.set_server_metadata(self.server_id, meta) |
| 33 | self.assertEqual(resp.status, 200) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 34 | |
| 35 | def test_list_server_metadata(self): |
| 36 | """All metadata key/value pairs for a server should be returned""" |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 37 | resp, resp_metadata = self.client.list_server_metadata(self.server_id) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 38 | |
| 39 | #Verify the expected metadata items are in the list |
| 40 | self.assertEqual(200, resp.status) |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 41 | expected = {'key1': 'value1', 'key2': 'value2'} |
| 42 | self.assertEqual(expected, resp_metadata) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 43 | |
| 44 | def test_set_server_metadata(self): |
| 45 | """The server's metadata should be replaced with the provided values""" |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 46 | #Create a new set of metadata for the server |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 47 | req_metadata = {'meta2': 'data2', 'meta3': 'data3'} |
| 48 | resp, metadata = self.client.set_server_metadata(self.server_id, |
| 49 | req_metadata) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 50 | self.assertEqual(200, resp.status) |
| 51 | |
| 52 | #Verify the expected values are correct, and that the |
| 53 | #previous values have been removed |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 54 | resp, resp_metadata = self.client.list_server_metadata(self.server_id) |
| 55 | self.assertEqual(resp_metadata, req_metadata) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 56 | |
David Kranz | 6e977a7 | 2012-02-13 09:34:05 -0500 | [diff] [blame^] | 57 | @attr(type='negative') |
gavin-brebner-orange | 9cc2334 | 2011-12-02 12:49:58 +0100 | [diff] [blame] | 58 | def test_server_create_metadata_key_too_long(self): |
| 59 | """ |
| 60 | Attempt to start a server with a meta-data key that is > 255 characters |
| 61 | Try a few values |
| 62 | """ |
| 63 | for sz in [256, 257, 511, 1023]: |
| 64 | key = "k" * sz |
| 65 | meta = {key: 'data1'} |
| 66 | name = rand_name('server') |
David Kranz | 6e977a7 | 2012-02-13 09:34:05 -0500 | [diff] [blame^] | 67 | try: |
| 68 | resp, server = self.client.create_server(name, self.image_ref, |
| 69 | self.flavor_ref, |
| 70 | meta=meta) |
| 71 | except: |
| 72 | pass |
| 73 | else: |
| 74 | self.fail('Metadata should have been too long') |
gavin-brebner-orange | 9cc2334 | 2011-12-02 12:49:58 +0100 | [diff] [blame] | 75 | # no teardown - all creates should fail |
| 76 | |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 77 | def test_update_server_metadata(self): |
| 78 | """ |
| 79 | The server's metadata values should be updated to the |
| 80 | provided values |
| 81 | """ |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 82 | meta = {'key1': 'alt1', 'key3': 'value3'} |
| 83 | resp, metadata = self.client.update_server_metadata(self.server_id, |
| 84 | meta) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 85 | self.assertEqual(200, resp.status) |
| 86 | |
| 87 | #Verify the values have been updated to the proper values |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 88 | resp, resp_metadata = self.client.list_server_metadata(self.server_id) |
| 89 | expected = {'key1': 'alt1', 'key2': 'value2', 'key3': 'value3'} |
| 90 | self.assertEqual(expected, resp_metadata) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 91 | |
| 92 | def test_get_server_metadata_item(self): |
| 93 | """ The value for a specic metadata key should be returned """ |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 94 | resp, meta = self.client.get_server_metadata_item(self.server_id, |
| 95 | 'key2') |
| 96 | self.assertTrue('value2', meta['key2']) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 97 | |
| 98 | def test_set_server_metadata_item(self): |
| 99 | """The item's value should be updated to the provided value""" |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 100 | #Update the metadata value |
| 101 | meta = {'nova': 'alt'} |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 102 | resp, body = self.client.set_server_metadata_item(self.server_id, |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 103 | 'nova', meta) |
| 104 | self.assertEqual(200, resp.status) |
| 105 | |
| 106 | #Verify the meta item's value has been updated |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 107 | resp, resp_metadata = self.client.list_server_metadata(self.server_id) |
| 108 | expected = {'key1': 'value1', 'key2': 'value2', 'nova': 'alt'} |
| 109 | self.assertEqual(expected, resp_metadata) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 110 | |
| 111 | def test_delete_server_metadata_item(self): |
| 112 | """The metadata value/key pair should be deleted from the server""" |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 113 | resp, meta = self.client.delete_server_metadata_item(self.server_id, |
| 114 | 'key1') |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 115 | self.assertEqual(204, resp.status) |
| 116 | |
| 117 | #Verify the metadata item has been removed |
Brian Waldon | 738cd63 | 2011-12-12 18:45:09 -0500 | [diff] [blame] | 118 | resp, resp_metadata = self.client.list_server_metadata(self.server_id) |
| 119 | expected = {'key2': 'value2'} |
| 120 | self.assertEqual(expected, resp_metadata) |
sapan-kona | 17d7f06 | 2011-12-22 17:35:00 +0530 | [diff] [blame] | 121 | |
| 122 | @attr(type='negative') |
| 123 | def test_get_nonexistant_server_metadata_item(self): |
| 124 | """Negative test: GET on nonexistant server should not succeed""" |
| 125 | try: |
| 126 | resp, meta = self.client.get_server_metadata_item(999, 'test2') |
| 127 | except: |
| 128 | pass |
| 129 | else: |
| 130 | self.fail('GET on nonexistant server should not succeed') |
| 131 | |
| 132 | @attr(type='negative') |
| 133 | def test_list_nonexistant_server_metadata(self): |
| 134 | """ |
| 135 | Negative test:List metadata on a non existant server should not succeed |
| 136 | """ |
| 137 | try: |
| 138 | resp, metadata = self.client.list_server_metadata(999) |
| 139 | except: |
| 140 | pass |
| 141 | else: |
| 142 | self.fail('List metadata on a non existant server should' |
| 143 | 'not succeed') |
| 144 | |
| 145 | @attr(type='negative') |
| 146 | def test_set_nonexistant_server_metadata(self): |
| 147 | """ |
| 148 | Negative test: Set metadata on a non existant server should not succeed |
| 149 | """ |
| 150 | meta = {'meta1': 'data1'} |
| 151 | try: |
| 152 | resp, metadata = self.client.set_server_metadata(999, meta) |
| 153 | except: |
| 154 | pass |
| 155 | else: |
| 156 | self.fail('Set metadata on a non existant server should' |
| 157 | 'not succeed') |
| 158 | |
| 159 | @attr(type='negative') |
| 160 | def test_update_nonexistant_server_metadata(self): |
| 161 | """ |
| 162 | Negative test: An update should not happen for a nonexistant image |
| 163 | """ |
| 164 | meta = {'key1': 'value1', 'key2': 'value2'} |
| 165 | try: |
| 166 | resp, metadata = self.client.update_server_metadata(999, meta) |
| 167 | except: |
| 168 | pass |
| 169 | else: |
| 170 | self.fail('An update should not happen for a nonexistant image') |
| 171 | |
| 172 | @attr(type='negative') |
| 173 | def test_delete_nonexistant_server_metadata_item(self): |
| 174 | """ |
| 175 | Negative test: Should not be able to delete metadata item from a |
| 176 | nonexistant server |
| 177 | """ |
David Kranz | 6e977a7 | 2012-02-13 09:34:05 -0500 | [diff] [blame^] | 178 | meta = {'d': 'delvalue'} |
sapan-kona | 17d7f06 | 2011-12-22 17:35:00 +0530 | [diff] [blame] | 179 | |
| 180 | #Delete the metadata item |
David Kranz | 6e977a7 | 2012-02-13 09:34:05 -0500 | [diff] [blame^] | 181 | try: |
| 182 | resp, metadata = self.client.delete_server_metadata_item(999, 'd') |
| 183 | except: |
| 184 | pass |
| 185 | else: |
| 186 | self.fail('A delete should not happen for a nonexistant image') |