diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-11-15 23:28:13 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-11-15 23:28:13 +0000 |
| commit | 9f3f056bd5ceda5d41508533244f5b509ddcfb0e (patch) | |
| tree | 2f056c66209065caa14cf2677bacb3a10f28a002 /nova/tests | |
| parent | a3090f2a3a8a83e25a4a4ded24785a8bb862fe87 (diff) | |
| parent | bcfff3dd530994d3ae22f945f429df3afc954cb0 (diff) | |
Merge "Follow hostname RFCs"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/test_servers.py | 5 | ||||
| -rw-r--r-- | nova/tests/test_compute.py | 24 | ||||
| -rw-r--r-- | nova/tests/test_utils.py | 24 |
3 files changed, 52 insertions, 1 deletions
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index aa9c5c02c..7f7e079db 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -1187,7 +1187,10 @@ class ServersControllerTest(test.TestCase): body = dict(server=inst_dict) def server_update(context, id, params): - filtered_dict = dict(display_name='server_test') + filtered_dict = { + 'display_name': 'server_test', + 'hostname': 'server-test', + } self.assertEqual(params, filtered_dict) return filtered_dict diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 1dfc781dd..6b74a14f0 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -1237,6 +1237,30 @@ class ComputeAPITestCase(BaseTestCase): db.instance_destroy(self.context, instance_id) + def test_hostname_create(self): + """Ensure instance hostname is set during creation.""" + inst_type = instance_types.get_instance_type_by_name('m1.tiny') + (instances, _) = self.compute_api.create(self.context, + inst_type, + None, + display_name='test host') + + self.assertEqual('test-host', instances[0]['hostname']) + + def test_hostname_update(self): + """Ensure instance hostname is set during an update.""" + instance_id = self._create_instance({"display_name": "test host"}) + instance = db.instance_get(self.context, instance_id) + + expected_hostname = 'test-host' + actual = self.compute_api.update(self.context, + instance_id, + **dict(instance)) + + self.assertEqual(expected_hostname, actual['hostname']) + + db.instance_destroy(self.context, instance_id) + def test_set_admin_password(self): """Ensure instance can have its admin password set""" instance_id = self._create_instance() diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index 19a15332d..2c4c02b82 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -282,6 +282,30 @@ class GenericUtilsTestCase(test.TestCase): result = utils.parse_server_string('www.exa:mple.com:8443') self.assertEqual(('', ''), result) + def test_hostname_unicode_sanitization(self): + hostname = u"\u7684.test.example.com" + self.assertEqual("test.example.com", + utils.sanitize_hostname(hostname)) + + def test_hostname_sanitize_periods(self): + hostname = "....test.example.com..." + self.assertEqual("test.example.com", + utils.sanitize_hostname(hostname)) + + def test_hostname_sanitize_dashes(self): + hostname = "----test.example.com---" + self.assertEqual("test.example.com", + utils.sanitize_hostname(hostname)) + + def test_hostname_sanitize_characters(self): + hostname = "(#@&$!(@*--#&91)(__=+--test-host.example!!.com-0+" + self.assertEqual("91----test-host.example.com-0", + utils.sanitize_hostname(hostname)) + + def test_hostname_translate(self): + hostname = "<}\x1fh\x10e\x08l\x02l\x05o\x12!{>" + self.assertEqual("hello", utils.sanitize_hostname(hostname)) + def test_bool_from_str(self): self.assertTrue(utils.bool_from_str('1')) self.assertTrue(utils.bool_from_str('2')) |
