Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame^] | 1 | from nose.plugins.attrib import attr |
| 2 | from storm import openstack |
| 3 | from storm.common.utils.data_utils import rand_name |
| 4 | import unittest2 as unittest |
| 5 | import storm.config |
| 6 | |
| 7 | |
| 8 | class ServerDetailsTest(unittest.TestCase): |
| 9 | |
| 10 | @classmethod |
| 11 | def setUpClass(cls): |
| 12 | cls.os = openstack.Manager() |
| 13 | cls.client = cls.os.servers_client |
| 14 | cls.config = storm.config.StormConfig() |
| 15 | cls.image_ref = cls.config.env.image_ref |
| 16 | cls.flavor_ref = cls.config.env.flavor_ref |
| 17 | cls.image_ref_alt = cls.config.env.image_ref_alt |
| 18 | cls.flavor_ref_alt = cls.config.env.flavor_ref_alt |
| 19 | |
| 20 | cls.s1_name = rand_name('server') |
| 21 | resp, server = cls.client.create_server(cls.s1_name, cls.image_ref, |
| 22 | cls.flavor_ref) |
| 23 | cls.client.wait_for_server_status(server['id'], 'ACTIVE') |
| 24 | resp, cls.s1 = cls.client.get_server(server['id']) |
| 25 | |
| 26 | cls.s2_name = rand_name('server') |
| 27 | resp, server = cls.client.create_server(cls.s2_name, cls.image_ref_alt, |
| 28 | cls.flavor_ref) |
| 29 | cls.client.wait_for_server_status(server['id'], 'ACTIVE') |
| 30 | resp, cls.s2 = cls.client.get_server(server['id']) |
| 31 | |
| 32 | cls.s3_name = rand_name('server') |
| 33 | resp, server = cls.client.create_server(cls.s3_name, cls.image_ref, |
| 34 | cls.flavor_ref_alt) |
| 35 | cls.client.wait_for_server_status(server['id'], 'ACTIVE') |
| 36 | resp, cls.s3 = cls.client.get_server(server['id']) |
| 37 | |
| 38 | @classmethod |
| 39 | def tearDownClass(cls): |
| 40 | cls.client.delete_server(cls.s1['id']) |
| 41 | cls.client.delete_server(cls.s2['id']) |
| 42 | cls.client.delete_server(cls.s3['id']) |
| 43 | |
| 44 | def test_list_servers_with_detail(self): |
| 45 | """ Return a detailed list of all servers """ |
| 46 | resp, body = self.client.list_servers_with_detail() |
| 47 | servers = body['servers'] |
| 48 | |
| 49 | self.assertTrue(self.s1 in servers) |
| 50 | self.assertTrue(self.s2 in servers) |
| 51 | self.assertTrue(self.s3 in servers) |
| 52 | |
| 53 | def test_list_servers_detailed_filter_by_image(self): |
| 54 | """Filter the detailed list of servers by image""" |
| 55 | params = {'image': self.image_ref} |
| 56 | resp, body = self.client.list_servers_with_detail(params) |
| 57 | servers = body['servers'] |
| 58 | |
| 59 | self.assertTrue(self.s1 in servers) |
| 60 | self.assertTrue(self.s2 not in servers) |
| 61 | self.assertTrue(self.s3 in servers) |
| 62 | |
| 63 | def test_list_servers_detailed_filter_by_flavor(self): |
| 64 | """Filter the detailed list of servers by flavor""" |
| 65 | params = {'flavor': self.flavor_ref_alt} |
| 66 | resp, body = self.client.list_servers_with_detail(params) |
| 67 | servers = body['servers'] |
| 68 | |
| 69 | self.assertTrue(self.s1 not in servers) |
| 70 | self.assertTrue(self.s2 not in servers) |
| 71 | self.assertTrue(self.s3 in servers) |
| 72 | |
| 73 | def test_list_servers_detailed_filter_by_server_name(self): |
| 74 | """Filter the detailed list of servers by server name""" |
| 75 | params = {'name': self.s1_name} |
| 76 | resp, body = self.client.list_servers_with_detail(params) |
| 77 | servers = body['servers'] |
| 78 | |
| 79 | self.assertTrue(self.s1 in servers) |
| 80 | self.assertTrue(self.s2 not in servers) |
| 81 | self.assertTrue(self.s3 not in servers) |
| 82 | |
| 83 | def test_list_servers_detailed_filter_by_server_status(self): |
| 84 | """Filter the detailed list of servers by server status""" |
| 85 | params = {'status': 'active'} |
| 86 | resp, body = self.client.list_servers_with_detail(params) |
| 87 | servers = body['servers'] |
| 88 | |
| 89 | self.assertTrue(self.s1 in servers) |
| 90 | self.assertTrue(self.s2 in servers) |
| 91 | self.assertTrue(self.s3 in servers) |
| 92 | |
| 93 | def test_get_server_details(self): |
| 94 | """Return the full details of a single server""" |
| 95 | resp, server = self.client.get_server(self.s1['id']) |
| 96 | |
| 97 | self.assertEqual(self.s1_name, server['name']) |
| 98 | self.assertEqual(self.image_ref, server['image']['id']) |
| 99 | self.assertEqual(str(self.flavor_ref), server['flavor']['id']) |