Skip to content

Commit

Permalink
[DM] Changes to image upgrade sanity
Browse files Browse the repository at this point in the history
Using the device disovered after running discovery playbook to test image upgrade.
Closes-Bug: #1775093

Change-Id: I888e726be4aa0084d2b4838b7f8736ad5c8c87a6
  • Loading branch information
sahanaspc committed Jun 11, 2018
1 parent a9d4dc2 commit f60f3a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 65 deletions.
Expand Up @@ -12,7 +12,3 @@ image:
image_version: 15.1X53-D63.9
image_family_name: juniper-qfx
image_vendor_name: juniper
device_family_name: juniper-qfx
device_vendor_name: juniper


Expand Up @@ -22,7 +22,6 @@
from vnc_api.gen.resource_client import Fabric
from vnc_api.gen.resource_client import FabricNamespace
from vnc_api.gen.resource_client import DeviceImage
from vnc_api.gen.resource_client import PhysicalRouter


# pylint: disable=E1101
Expand Down Expand Up @@ -181,13 +180,10 @@ def add_asn_namespace(self, fab, asn):
return namespace
# end _add_asn_namespace

def create_image_and_device(self, img_name, img_uri, img_version,
img_family, img_vendor, device_family,
device_vendor, prouter_ip, prouter_password, device_name):

"""create image and physical device"""
def create_image(self, img_name, img_uri, img_version,
img_family, img_vendor):
"""create image"""
img_fqname = None
device_fqname = None
try:
self._logger.info('Creating image: %s', img_name)
img_fqname = ['default-global-system-config', img_name]
Expand All @@ -210,34 +206,9 @@ def create_image_and_device(self, img_name, img_uri, img_version,
self._logger.debug(
"Image created:\n%s",
pprint.pformat(self._api.obj_to_dict(image), indent=4))
return image

try:
self._logger.info('Creating device: %s', device_name)
device_fqname = ['default-global-system-config', device_name]
device = PhysicalRouter(
name=device_name,
fq_name=device_fqname,
physical_router_device_family=device_family,
physical_router_management_ip=prouter_ip,
physical_router_vendor_name=device_vendor,
physical_router_user_credentials={
'username': 'root', 'password': prouter_password
}
)
device_uuid = self._api.physical_router_create(device)
device = self._api.physical_router_read(id=device_uuid)

except RefsExistError:
self._logger.warn("Device '%s' already exists", device_name)
device = self._api.physical_router_read(fq_name=device_fqname)

self._logger.debug(
"Device created:\n%s",
pprint.pformat(self._api.obj_to_dict(device), indent=4))

return image, device

# end create_image_and_device
# end create_image

def cleanup_fabric(self, fab_name):
"""delete fabric including all prouters in the fabric"""
Expand Down Expand Up @@ -266,7 +237,7 @@ def cleanup_fabric(self, fab_name):
self._logger.warn('Fabric "%s" not found', fab_name)
# end cleanup_fabric

def cleanup_image_prouter(self, img_name, device_name):
def cleanup_image(self, img_name,):
# image cleanup
self._logger.info("Clean up image and prouter from db")
try:
Expand All @@ -279,18 +250,6 @@ def cleanup_image_prouter(self, img_name, device_name):
except NoIdError:
self._logger.warn('Image "%s" not found', img_name)

# device cleanup
try:
device_fqname = ['default-global-system-config', device_name]
device = self._api.physical_router_read(fq_name=device_fqname)
self._logger.debug(
"Delete Physical Router: %s", device_fqname)
self._api.physical_router_delete(device_fqname)
except NoIdError:
self._logger.warn('Device "%s" not found', device_name)

# end cleanup_image_prouter

def _delete_prouter(self, uuid):
prouter = self._api.physical_router_read(id=uuid)

Expand Down
Expand Up @@ -56,9 +56,10 @@ class SanityTest02(SanityBase):

def __init__(self, cfg):
SanityBase.__init__(self, cfg, "sanity_test_02")
self._namespaces = cfg['namespaces']
self._prouter = cfg['prouter']
self._prouter_ip = cfg['prouter']['ips'][0]
self._prouter_password = cfg['prouter']['passwords'][0]
self._device_name = 'mxdev'
self._swift_params = cfg['swift']
self._image_details = cfg['image']
self._keystone_ip = self._swift_params['keystone_ip']
Expand All @@ -67,8 +68,6 @@ def __init__(self, cfg):
self._image_version = self._image_details['image_version']
self._image_family_name = self._image_details['image_family_name']
self._image_vendor_name = self._image_details['image_vendor_name']
self._device_family_name = self._image_details['device_family_name']
self._device_vendor_name = self._image_details['device_vendor_name']
self._auth_url = 'http://' + self._keystone_ip + ':' + str(self._port) \
+ '/v3'
try:
Expand Down Expand Up @@ -114,28 +113,33 @@ def test_image_upgrade(self):
self._exit_with_error(
"Could not upload image file to swift: %s" % str(ex))

# Test image upgrade
# Test image upgrade after device discovery
try:
# Create image and device db objects
image, device = self.create_image_and_device(self._image_name,
self.cleanup_fabric('fab01')
fabric = self.create_fabric('fab01', self._prouter['passwords'])
mgmt_namespace = self._namespaces['management']
self.add_mgmt_ip_namespace(fabric, mgmt_namespace['name'],
mgmt_namespace['cidrs'])
self.add_asn_namespace(fabric, self._namespaces['asn'])

prouters = self.discover_fabric_device(fabric)
print prouters
# Create image db object
image = self.create_image(self._image_name,
img_uri,
self._image_version,
self._image_family_name,
self._image_vendor_name,
self._device_family_name,
self._device_vendor_name,
self._prouter_ip,
self._prouter_password,
self._device_name)
)
# Run image upgrade playbook
self.image_upgrade(image, device)
self.image_upgrade(image, prouters[0])
except Exception as ex:
self._exit_with_error(
"Image upgrade test failed due to unexpected error: %s"
% str(ex))

# clean device and image from DB
self.cleanup_image_prouter(self._image_name, self._device_name)
# clean image from DB
self.cleanup_image(self._image_name)
# end test

def _getmd5(self, filepath):
Expand Down

0 comments on commit f60f3a1

Please sign in to comment.