Skip to content

Commit

Permalink
Azure HA | Updated HAD tester
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-yairra authored Jun 20, 2024
1 parent dddc8ce commit b46e71d
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions azure/misc/azure_ha_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@


def set_arm_versions():
"""#TODO fixDocstring"""
global ARM_VERSIONS
log('Setting api versions for "%s" solution\n' % templateName)
if templateName == 'stack-ha':
Expand All @@ -47,14 +48,17 @@ def set_arm_versions():


def is_azure():
"""#TODO fixDocstring"""
return os.path.isfile('/etc/in-azure')


def log(msg):
"""#TODO fixDocstring"""
sys.stderr.write(msg)


def test_rw(rid, allow_not_found=False):
def test_rw(rid, allow_not_found=False, test_write=True):
"""#TODO fixDocstring"""
components = rid.split('/')
log('Id : %s\n' % rid)
log('Subscription : %s\n' % components[2])
Expand All @@ -69,18 +73,19 @@ def test_rw(rid, allow_not_found=False):
log('Attempting to read - [%s]\n' % e.reason)
raise
log('Attempting to read - [OK]\n')

log('Attempting to write ')
try:
azure.arm('PUT', rid + ARM_VERSIONS['resources'], json.dumps(obj))
except rest.RequestException as e:
log('- [%s]\n' % e.reason)
raise
log('- [OK]\n')
if test_write:
log('Attempting to write ')
try:
azure.arm('PUT', rid + ARM_VERSIONS['resources'], json.dumps(obj))
except rest.RequestException as e:
log('- [%s]\n' % e.reason)
raise
log('- [OK]\n')
return obj


def get_vm_primary_nic(vm):
"""#TODO fixDocstring"""
nis = vm['properties']['networkProfile']['networkInterfaces']
if len(nis) == 1:
ni = nis[0]
Expand All @@ -92,13 +97,14 @@ def get_vm_primary_nic(vm):


def test_cluster_ip():
"""#TODO fixDocstring"""
def test_vip(vip_resource):
if '/' in vip_resource:
cluster_ip_id = vip_resource
else:
cluster_ip_id = conf['baseId'] + \
'Microsoft.Network/publicIPAddresses/' + vip_resource
test_rw(cluster_ip_id, allow_not_found=True)
test_rw(cluster_ip_id, allow_not_found=True, test_write=False)

for interface in conf['clusterNetworkInterfaces']:
if isinstance(conf['clusterNetworkInterfaces'][interface][0], dict):
Expand All @@ -110,6 +116,7 @@ def test_vip(vip_resource):


def test_load_balancer():
"""#TODO fixDocstring"""
load_balancer_nm = conf.get('lbName', '')
if not load_balancer_nm:
log('An external load balancer name is not configured.\n')
Expand All @@ -122,6 +129,7 @@ def test_load_balancer():


def vnet_rg():
"""#TODO fixDocstring"""
local_vm = azure.arm('GET', conf['baseId'] +
'microsoft.compute/virtualmachines/' +
conf['hostname'])[1]
Expand All @@ -132,6 +140,7 @@ def vnet_rg():


def get_route_table_ids_for_vnet(vnet):
"""#TODO fixDocstring"""
route_table_ids = set()
for subnet in vnet['properties'].get('subnets', []):
if subnet['properties'].get('routeTable'):
Expand All @@ -140,6 +149,7 @@ def get_route_table_ids_for_vnet(vnet):


def get_vnet_id():
"""#TODO fixDocstring"""
vnet_id = conf.get('vnetId')
if vnet_id:
return vnet_id
Expand All @@ -154,6 +164,7 @@ def get_vnet_id():


def get_route_table_ids_for_peering(vnet):
"""#TODO fixDocstring"""
route_table_ids = set()

for peering in vnet['properties'].get('virtualNetworkPeerings', []):
Expand All @@ -174,6 +185,7 @@ def get_route_table_ids_for_peering(vnet):


def get_route_table_ids():
"""#TODO fixDocstring"""
route_table_ids = set()

vnet_id = get_vnet_id()
Expand All @@ -186,6 +198,7 @@ def get_route_table_ids():


def interfaces_test_rw(interface_id):
"""#TODO fixDocstring"""
interface = test_rw(interface_id['id'])
if not interface['properties'].get('enableIPForwarding'):
raise Exception(
Expand All @@ -194,6 +207,7 @@ def interfaces_test_rw(interface_id):


def test_cluster_parameters():
"""#TODO fixDocstring"""
path = "/var/opt/fw.boot/modules/fwkern.conf"
text1 = "fwha_dead_timeout_multiplier=20"
text2 = "fwha_if_problem_tolerance=200"
Expand Down Expand Up @@ -234,6 +248,7 @@ def test_cluster_parameters():


def test():
"""#TODO fixDocstring"""
global conf

if not is_azure():
Expand Down Expand Up @@ -375,7 +390,7 @@ def test():
else:
interfaces_test_rw(interface_id)

if templateName != 'ha':
if templateName not in ['ha', 'ha_terraform']:
log('Testing authorization on routing tables...\n')
for route_table in get_route_table_ids():
test_rw(route_table)
Expand All @@ -397,6 +412,7 @@ def test():


def main():
"""#TODO fixDocstring"""
try:
test()
except Exception:
Expand Down

0 comments on commit b46e71d

Please sign in to comment.