Skip to content

Commit

Permalink
svc_monitor scheduling does not handle empty azs
Browse files Browse the repository at this point in the history
The change handles cases where either the entire nova az is diabled
or few hosts in the az are disabled or nova-commpute is not
running on any of the hosts.

Change-Id: If074c9dd289c93235c9a9106f1c6db01147313bf
Closes-Bug: #1561609
  • Loading branch information
varun_lodaya committed Apr 4, 2016
1 parent 92fd19b commit 57655fc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/config/svc-monitor/svc_monitor/scheduler/vrouter_scheduler.py
Expand Up @@ -63,14 +63,29 @@ def _get_az_vrouter_list(self):
for az in az_list:
if self._args.netns_availability_zone not in str(az):
continue
az_vr_list.extend(az.hosts.keys())
try:
# check if the az is available
if not az.zoneState['available']:
continue
# check if there are any hosts
if not az.hosts:
continue
# check if hosts are active & enabled
for host,host_status in az.hosts.iteritems():
if (('nova-compute' in host_status) and \
host_status['nova-compute']['available'] and \
host_status['nova-compute']['active']):
az_vr_list.append(host)
except Exception as e:
self._logger.error(str(e))
continue

return az_vr_list

def get_analytics_client(self):
try:
sub_obj = self._disc.subscribe(analytics_svc_name, 0)
slist= sub_obj.info
slist = sub_obj.info
except Exception as ex:
self._logger.error('Failed to get analytics api from discovery')
return None
Expand Down
Expand Up @@ -19,7 +19,7 @@

import mock
import unittest

import six
import cfgm_common.analytics_client as analytics
import cfgm_common.svc_info as svc_info
from sandesh_common.vns import constants
Expand Down Expand Up @@ -144,3 +144,54 @@ def side_effect(seq):
self.assertEqual(chosen_vrouter, 'vrouter1')

random_patch.stop()

def test_disabled_azs(self):
class FakeAvailabilityZone(object):
def __repr__(self):
return "<AvailabilityZone: %s>" % self.zoneName
def __init__(self, info):
self._info = info
self._add_details(info)

def _add_details(self, info):
for (k, v) in six.iteritems(info):
try:
setattr(self, k, v)
self._info[k] = v
except AttributeError:
pass

def get_fake_azs():
az1_info = {"zoneState":{"available":True},
"hosts":{"compute1":{"nova-compute":
{"available":True,"active":True}},
"compute2":{"nova-compute":
{"available":False,"active":True}},
"compute3":{"nova-compute":
{ "available":True,"active":True}}},
"zoneName":"fake_az1"}

az2_info = {"zoneState":{"available":False},
"hosts":{"compute4":{"nova-compute":
{"available":True,"active":True}}},
"zoneName":"fake_az2"}

az3_info = {"zoneState":{"available":True},
"hosts":{"compute5":{"nova-compute":
{"available":True,"active":True}}},
"zoneName":"fake_az3"}


return [FakeAvailabilityZone(az1_info),FakeAvailabilityZone(az2_info),
FakeAvailabilityZone(az3_info)]

self.mock_nc = mock.MagicMock()
self.mock_nc.oper = mock.Mock(return_value=get_fake_azs())

self.scheduler2 = \
scheduler.RandomScheduler(vnc_lib=self.vnc_mock, nova_client=self.mock_nc,
disc=mock.MagicMock(), logger=mock.MagicMock(),
args=mock.MagicMock(netns_availability_zone="fake_az1"))

az_vr_list = self.scheduler2._get_az_vrouter_list()
self.assertEqual(az_vr_list, ['compute1', 'compute3'])

0 comments on commit 57655fc

Please sign in to comment.