Daryl Walleck | adea1fa | 2011-11-15 18:36:39 -0600 | [diff] [blame] | 1 | import unittest2 as unittest |
| 2 | import storm.config |
| 3 | import base64 |
| 4 | from nose.plugins.attrib import attr |
| 5 | from storm import openstack |
| 6 | from storm.common.utils.data_utils import rand_name |
| 7 | from storm.common import ssh |
| 8 | from storm import exceptions |
| 9 | |
| 10 | |
| 11 | class ServersNegativeTest(unittest.TestCase): |
| 12 | |
| 13 | @classmethod |
| 14 | def setUpClass(cls): |
| 15 | cls.os = openstack.Manager() |
| 16 | cls.client = cls.os.servers_client |
| 17 | cls.config = storm.config.StormConfig() |
| 18 | cls.image_ref = cls.config.env.image_ref |
| 19 | cls.flavor_ref = cls.config.env.flavor_ref |
| 20 | cls.ssh_timeout = cls.config.nova.ssh_timeout |
| 21 | |
| 22 | def test_server_name_blank(self): |
| 23 | """Create a server with name parameter empty""" |
| 24 | try: |
| 25 | resp, server = self.client.create_server('', self.image_ref, |
| 26 | self.flavor_ref) |
| 27 | except exceptions.BadRequest: |
| 28 | pass |
| 29 | else: |
| 30 | self.fail('Server name cannot be blank') |
| 31 | |
| 32 | def test_personality_file_contents_not_encoded(self): |
| 33 | """Use an unencoded file when creating a server with personality""" |
| 34 | file_contents = 'This is a test file.' |
| 35 | personality = [{'path': '/etc/testfile.txt', |
| 36 | 'contents': file_contents}] |
| 37 | |
| 38 | try: |
| 39 | resp, server = self.client.create_server('test', |
| 40 | self.image_ref, |
| 41 | self.flavor_ref, |
| 42 | personality=personality) |
| 43 | except exceptions.BadRequest: |
| 44 | pass |
| 45 | else: |
| 46 | self.fail('Unencoded file contents should not be accepted') |
| 47 | |
| 48 | def test_create_with_invalid_image(self): |
| 49 | """Create a server with an unknown image""" |
| 50 | try: |
| 51 | resp, server = self.client.create_server('fail', -1, |
| 52 | self.flavor_ref) |
| 53 | except exceptions.BadRequest: |
| 54 | pass |
| 55 | else: |
| 56 | self.fail('Cannot create a server with an invalid image') |
| 57 | |
| 58 | def test_create_with_invalid_flavor(self): |
| 59 | """Create a server with an unknown flavor""" |
| 60 | try: |
| 61 | self.client.create_server('fail', self.image_ref, -1) |
| 62 | except exceptions.BadRequest: |
| 63 | pass |
| 64 | else: |
| 65 | self.fail('Cannot create a server with an invalid flavor') |
| 66 | |
| 67 | @unittest.expectedFailure |
| 68 | def test_invalid_access_ip_v4_address(self): |
| 69 | """An access IPv4 address must match a valid address pattern""" |
| 70 | #Currently failing due to bug |
| 71 | accessIPv4 = '1.1.1.1.1.1' |
| 72 | name = rand_name('server') |
| 73 | try: |
| 74 | resp, server = self.client.create_server(name, |
| 75 | self.image_ref, |
| 76 | self.flavor_ref, |
| 77 | accessIPv4=accessIPv4) |
| 78 | except exceptions.BadRequest: |
| 79 | pass |
| 80 | else: |
| 81 | self.fail('Access IPv4 address must match the correct format') |
| 82 | |
| 83 | @unittest.expectedFailure |
| 84 | def test_invalid_ip_v6_address(self): |
| 85 | """An access IPv6 address must match a valid address pattern""" |
| 86 | #Currently failing due to bug |
| 87 | accessIPv6 = 'notvalid' |
| 88 | name = rand_name('server') |
| 89 | try: |
| 90 | resp, server = self.client.create_server(name, |
| 91 | self.image_ref, |
| 92 | self.flavor_ref, |
| 93 | accessIPv6=accessIPv6) |
| 94 | except exceptions.BadRequest: |
| 95 | pass |
| 96 | else: |
| 97 | self.fail('Access IPv6 address must match the correct format') |