477
488
'hostname': json.dumps(hosts)}
479
490
if relation_prefix:
491
for key in list(kwargs.keys()):
482
492
kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key]
485
495
for rid in relation_ids('shared-db'):
486
496
relation_set(relation_id=rid, **kwargs)
499
def os_requires_version(ostack_release, pkg):
501
Decorator for hook to specify minimum supported release
505
def wrapped_f(*args):
506
if os_release(pkg) < ostack_release:
507
raise Exception("This hook is not supported on releases"
508
" before %s" % ostack_release)
514
def git_install_requested():
515
"""Returns true if openstack-origin-git is specified."""
516
return config('openstack-origin-git') != "None"
519
requirements_dir = None
522
def git_clone_and_install(file_name, core_project):
523
"""Clone/install all OpenStack repos specified in yaml config file."""
524
global requirements_dir
526
if file_name == "None":
529
yaml_file = os.path.join(charm_dir(), file_name)
531
# clone/install the requirements project first
532
installed = _git_clone_and_install_subset(yaml_file,
533
whitelist=['requirements'])
534
if 'requirements' not in installed:
535
error_out('requirements git repository must be specified')
537
# clone/install all other projects except requirements and the core project
538
blacklist = ['requirements', core_project]
539
_git_clone_and_install_subset(yaml_file, blacklist=blacklist,
540
update_requirements=True)
542
# clone/install the core project
543
whitelist = [core_project]
544
installed = _git_clone_and_install_subset(yaml_file, whitelist=whitelist,
545
update_requirements=True)
546
if core_project not in installed:
547
error_out('{} git repository must be specified'.format(core_project))
550
def _git_clone_and_install_subset(yaml_file, whitelist=[], blacklist=[],
551
update_requirements=False):
552
"""Clone/install subset of OpenStack repos specified in yaml config file."""
553
global requirements_dir
556
with open(yaml_file, 'r') as fd:
557
projects = yaml.load(fd)
558
for proj, val in projects.items():
559
# The project subset is chosen based on the following 3 rules:
560
# 1) If project is in blacklist, we don't clone/install it, period.
561
# 2) If whitelist is empty, we clone/install everything else.
562
# 3) If whitelist is not empty, we clone/install everything in the
564
if proj in blacklist:
566
if whitelist and proj not in whitelist:
568
repo = val['repository']
569
branch = val['branch']
570
repo_dir = _git_clone_and_install_single(repo, branch,
572
if proj == 'requirements':
573
requirements_dir = repo_dir
574
installed.append(proj)
578
def _git_clone_and_install_single(repo, branch, update_requirements=False):
579
"""Clone and install a single git repository."""
580
dest_parent_dir = "/mnt/openstack-git/"
581
dest_dir = os.path.join(dest_parent_dir, os.path.basename(repo))
583
if not os.path.exists(dest_parent_dir):
584
juju_log('Host dir not mounted at {}. '
585
'Creating directory there instead.'.format(dest_parent_dir))
586
os.mkdir(dest_parent_dir)
588
if not os.path.exists(dest_dir):
589
juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
590
repo_dir = install_remote(repo, dest=dest_parent_dir, branch=branch)
594
if update_requirements:
595
if not requirements_dir:
596
error_out('requirements repo must be cloned before '
597
'updating from global requirements.')
598
_git_update_requirements(repo_dir, requirements_dir)
600
juju_log('Installing git repo from dir: {}'.format(repo_dir))
601
pip_install(repo_dir)
606
def _git_update_requirements(package_dir, reqs_dir):
607
"""Update from global requirements.
609
Update an OpenStack git directory's requirements.txt and
610
test-requirements.txt from global-requirements.txt."""
611
orig_dir = os.getcwd()
613
cmd = "python update.py {}".format(package_dir)
615
subprocess.check_call(cmd.split(' '))
616
except subprocess.CalledProcessError:
617
package = os.path.basename(package_dir)
618
error_out("Error updating {} from global-requirements.txt".format(package))