Merge "Instance details view shows hostname (if it has it) or IP"

This commit is contained in:
Jenkins 2014-01-23 01:49:55 +00:00 committed by Gerrit Code Review
commit 339a811687
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_ swift_url = http://localhost:8080/v1/AUTH_
# Config option for showing the IP address that nova doles out # Config option for showing the IP address that nova doles out
add_addresses = True
network_label_regex = ^private$ network_label_regex = ^private$
#ip_regex = ^(15.|123.) #ip_regex = ^(15.|123.)

View File

@ -70,7 +70,6 @@ nova_service_type = compute
nova_service_name = Compute Service nova_service_name = Compute Service
# Config option for showing the IP address that nova doles out # Config option for showing the IP address that nova doles out
add_addresses = True
network_label_regex = ^private$ network_label_regex = ^private$
ip_regex = ^(15.|123.) ip_regex = ^(15.|123.)

View File

@ -41,9 +41,6 @@ common_opts = [
cfg.StrOpt('api_paste_config', cfg.StrOpt('api_paste_config',
default="api-paste.ini", default="api-paste.ini",
help='File name for the paste.deploy config for trove-api'), 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', cfg.BoolOpt('trove_volume_support',
default=True, default=True,
help='Whether to provision a cinder volume for datadir'), help='Whether to provision a cinder volume for datadir'),

View File

@ -95,11 +95,9 @@ class InstanceDetailView(InstanceView):
result['instance']['datastore']['version'] = (self.instance. result['instance']['datastore']['version'] = (self.instance.
datastore_version.name) datastore_version.name)
dns_support = CONF.trove_dns_support if self.instance.hostname:
if dns_support:
result['instance']['hostname'] = self.instance.hostname result['instance']['hostname'] = self.instance.hostname
else:
if CONF.add_addresses:
ip = get_ip_address(self.instance.addresses) ip = get_ip_address(self.instance.addresses)
if ip is not None and len(ip) > 0: if ip is not None and len(ip) > 0:
result['instance']['ip'] = ip result['instance']['ip'] = ip

View File

@ -13,10 +13,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from mock import Mock
from testtools import TestCase from testtools import TestCase
from trove.common import cfg from trove.common import cfg
from trove.instance.views import get_ip_address from trove.instance.views import get_ip_address
from trove.instance.views import filter_ips from trove.instance.views import filter_ips
from trove.instance.views import InstanceView
from trove.instance.views import InstanceDetailView
CONF = cfg.CONF CONF = cfg.CONF
@ -68,3 +71,50 @@ class InstanceViewsTest(TestCase):
self.assertTrue(len(ip) == 2) self.assertTrue(len(ip) == 2)
self.assertTrue('123.123.123.123' in ip) self.assertTrue('123.123.123.123' in ip)
self.assertTrue('15.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'])