Skip to content

Commit

Permalink
Closes-Bug: #1594994
Browse files Browse the repository at this point in the history
Support for adding the storage image tgz

Change-Id: I635d463f1f6d71353d871516ee024c730cdfdcb6
  • Loading branch information
sgurumurthy committed Jul 26, 2016
1 parent 91289f4 commit f19c831
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions src/server_mgr_main.py
Expand Up @@ -1498,6 +1498,8 @@ def put_image(self):
image_path = image.get("path", None)
image_category = image.get("category", None)
image_params = image.get("parameters", {})
#Convert unicode python string dictionary into a normal string dict
image_params = ast.literal_eval(image_params)
if (not image_id) or (not image_path):
self._smgr_log.log(self._smgr_log.ERROR,
"image id or location not specified")
Expand All @@ -1522,6 +1524,9 @@ def put_image(self):
msg = "image not found at %s" % \
(image_path)
raise ServerMgrException(msg, ERR_OPR_ERROR)
#Get the file type
cmd = 'file %s'%image_path
output = subprocess.check_output(cmd, shell=True)
if ((image_type == "contrail-centos-package") or
(image_type == "contrail-ubuntu-package") ):
if not self.validate_package_id(image_id):
Expand All @@ -1535,9 +1540,6 @@ def put_image(self):
image_params['sequence_provisioning_available'] = sequence_provisioning_available
if puppet_version not in image_params:
image_params['puppet_version'] = puppet_version
#Get the file type
cmd = 'file %s'%image_path
output = subprocess.check_output(cmd, shell=True)
#Check if the package is a tgz or deb and get its version
if output and 'gzip compressed data' in output:
mirror = self._args.html_root_dir+"contrail/repo/"+image_id
Expand All @@ -1557,9 +1559,18 @@ def put_image(self):
elif image_type == "contrail-storage-ubuntu-package":
self._create_repo(
image_id, image_type, image_version, image_path)
version = subprocess.check_output(['dpkg-deb', '-f',image_path,'Version'])
version = version.strip('\n')
image_params['version'] = version.split('~')[0]
if output and 'gzip compressed data' in output:
sm = ServerMgrUtil()
version = sm.get_package_version(os.path.basename(image_path))
p = re.compile("[0-9].*")
for m in p.finditer(version):
match_index = m.start(0)
version = str(version.strip('\n'))
image_params['version'] = version[match_index:-5]
else:
version = subprocess.check_output(['dpkg-deb', '-f',image_path,'Version'])
version = version.strip('\n')
image_params['version'] = version.split('~')[0]
else:
image_kickstart = image_params.get('kickstart', '')
image_kickseed = image_params.get('kickseed', '')
Expand Down Expand Up @@ -2306,23 +2317,31 @@ def _create_storage_deb_repo(
cmd = "cp -f %s %s" %(
dest, mirror)
subprocess.check_call(cmd, shell=True)
# Extract .tgz of other packages from the repo
cmd = (
"dpkg -x %s . > /dev/null" %(dest))
subprocess.check_call(cmd, shell=True)
cmd = ("mv ./opt/contrail/contrail_packages/contrail_storage_debs.tgz .")
cmd = 'file %s'%dest
output = subprocess.check_output(cmd, shell=True)
#Check if the package is a tgz or deb and get its version
if output and 'gzip compressed data' in output:
cmd = ("tar xvzf %s > /dev/null" %(dest))
elif 'Debian binary package' in output:
# Extract .tgz of other packages from the repo
cmd = (
"dpkg -x %s . > /dev/null" %(dest))
subprocess.check_call(cmd, shell=True)
if 'Debian binary package' in output:
cmd = ("mv ./opt/contrail/contrail_packages/contrail_storage_debs.tgz .")
subprocess.check_call(cmd, shell=True)

# check if its a new version where repo pinning changes are brought in
if os.path.isfile('./opt/contrail/contrail_packages/.repo_pinning'):
repo_pinning = True
else:
repo_pinning = False
cmd = ("rm -rf opt")
subprocess.check_call(cmd, shell=True)
# untar tgz to get all packages
cmd = ("tar xvzf contrail_storage_debs.tgz > /dev/null")
subprocess.check_call(cmd, shell=True)
if 'Debian binary package' in output:
cmd = ("rm -rf opt")
subprocess.check_call(cmd, shell=True)
# untar tgz to get all packages
cmd = ("tar xvzf contrail_storage_debs.tgz > /dev/null")
subprocess.check_call(cmd, shell=True)
# remove the tgz file itself, not needed any more
cmd = ("rm -f contrail_storage_debs.tgz")
subprocess.check_call(cmd, shell=True)
Expand Down

0 comments on commit f19c831

Please sign in to comment.