From 33ebe3c21ddd90b95d249549dc67f4472cc892aa Mon Sep 17 00:00:00 2001 From: Steve Leon Date: Thu, 12 Dec 2013 17:43:32 -0800 Subject: [PATCH] Instance details view shows hostname (if it has it) or IP Currently the hostname and IP is controlled by two config values: trove_dns_support and add_addresses. I dont see a point of having the hostname and IP indenpendent. It causes issues for old instances when DNS is enabled. I propose to simplify the view by showing hostname if it is set or show the IP if it is not set. Closes-bug: #1260567 Change-Id: Ia1fd47cbee89b10d53b0821e104a34eb31543846 --- etc/trove/trove.conf.sample | 1 - etc/trove/trove.conf.test | 1 - trove/common/cfg.py | 3 -- trove/instance/views.py | 6 +-- .../unittests/instance/test_instance_views.py | 50 +++++++++++++++++++ 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/etc/trove/trove.conf.sample b/etc/trove/trove.conf.sample index 2af0eb79af..f5871e0290 100644 --- a/etc/trove/trove.conf.sample +++ b/etc/trove/trove.conf.sample @@ -46,7 +46,6 @@ cinder_url = http://localhost:8776/v1 swift_url = http://localhost:8080/v1/AUTH_ # Config option for showing the IP address that nova doles out -add_addresses = True network_label_regex = ^private$ #ip_regex = ^(15.|123.) diff --git a/etc/trove/trove.conf.test b/etc/trove/trove.conf.test index f88d008310..5ba77af906 100644 --- a/etc/trove/trove.conf.test +++ b/etc/trove/trove.conf.test @@ -70,7 +70,6 @@ nova_service_type = compute nova_service_name = Compute Service # Config option for showing the IP address that nova doles out -add_addresses = True network_label_regex = ^private$ ip_regex = ^(15.|123.) diff --git a/trove/common/cfg.py b/trove/common/cfg.py index d657b2e59f..863a9f52db 100644 --- a/trove/common/cfg.py +++ b/trove/common/cfg.py @@ -41,9 +41,6 @@ common_opts = [ cfg.StrOpt('api_paste_config', default="api-paste.ini", help='File name for the paste.deploy config for trove-api'), - cfg.BoolOpt('add_addresses', - default=False, - help='Whether to add IP addresses to the list operations'), cfg.BoolOpt('trove_volume_support', default=True, help='File name for the paste.deploy config for trove-api'), diff --git a/trove/instance/views.py b/trove/instance/views.py index 2786929f5a..b159767224 100644 --- a/trove/instance/views.py +++ b/trove/instance/views.py @@ -92,11 +92,9 @@ class InstanceDetailView(InstanceView): result['instance']['datastore']['version'] = (self.instance. datastore_version.name) - dns_support = CONF.trove_dns_support - if dns_support: + if self.instance.hostname: result['instance']['hostname'] = self.instance.hostname - - if CONF.add_addresses: + else: ip = get_ip_address(self.instance.addresses) if ip is not None and len(ip) > 0: # Includes ip addresses that match the regexp pattern diff --git a/trove/tests/unittests/instance/test_instance_views.py b/trove/tests/unittests/instance/test_instance_views.py index 55f6133f35..e6a095cc23 100644 --- a/trove/tests/unittests/instance/test_instance_views.py +++ b/trove/tests/unittests/instance/test_instance_views.py @@ -13,10 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. # +from mock import Mock from testtools import TestCase from trove.common import cfg from trove.instance.views import get_ip_address from trove.instance.views import filter_ips +from trove.instance.views import InstanceView +from trove.instance.views import InstanceDetailView CONF = cfg.CONF @@ -68,3 +71,50 @@ class InstanceViewsTest(TestCase): self.assertTrue(len(ip) == 2) self.assertTrue('123.123.123.123' in ip) self.assertTrue('15.123.123.123' in ip) + + +class InstanceDetailViewTest(TestCase): + + def setUp(self): + super(InstanceDetailViewTest, self).setUp() + self.build_links_method = InstanceView._build_links + self.build_flavor_links_method = InstanceView._build_flavor_links + InstanceView._build_links = Mock() + InstanceView._build_flavor_links = Mock() + self.instance = Mock() + self.instance.created = 'Yesterday' + self.instance.updated = 'Now' + self.instance.datastore_version = Mock() + self.instance.datastore_version.name = 'mysql_test_version' + self.instance.hostname = 'test.trove.com' + self.ip = "1.2.3.4" + self.instance.addresses = {"private": [{"addr": self.ip}]} + self.instance.volume_used = '3' + self.instance.root_password = 'iloveyou' + + def tearDown(self): + super(InstanceDetailViewTest, self).tearDown() + InstanceView._build_links = self.build_links_method + InstanceView._build_flavor_links = self.build_flavor_links_method + + def test_data_hostname(self): + view = InstanceDetailView(self.instance, Mock()) + result = view.data() + self.assertEqual(self.instance.created, result['instance']['created']) + self.assertEqual(self.instance.updated, result['instance']['updated']) + self.assertEqual(self.instance.datastore_version.name, + result['instance']['datastore']['version']) + self.assertEqual(self.instance.hostname, + result['instance']['hostname']) + self.assertNotIn('ip', result['instance']) + + def test_data_ip(self): + self.instance.hostname = None + view = InstanceDetailView(self.instance, Mock()) + result = view.data() + self.assertEqual(self.instance.created, result['instance']['created']) + self.assertEqual(self.instance.updated, result['instance']['updated']) + self.assertEqual(self.instance.datastore_version.name, + result['instance']['datastore']['version']) + self.assertNotIn('hostname', result['instance']) + self.assertEqual([self.ip], result['instance']['ip'])