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: I117e841ab1d56aa1df57d48c315d2988830f52cf
Closes-Bug: #1561609
  • Loading branch information
varun_lodaya committed Apr 4, 2016
1 parent 8e7e429 commit f0118b6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Expand Up @@ -63,7 +63,22 @@ 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.log_error(str(e))
continue

return az_vr_list

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 @@ -145,3 +145,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 f0118b6

Please sign in to comment.