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
This commit is contained in:
Steve Leon 2013-12-12 17:43:32 -08:00
parent 1ebc9347cc
commit 33ebe3c21d
5 changed files with 52 additions and 9 deletions

View File

@ -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.)

View File

@ -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.)

View File

@ -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'),

View File

@ -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

View File

@ -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'])