471
490
def git_install_requested():
472
"""Returns true if openstack-origin-git is specified."""
473
return config('openstack-origin-git') != "None"
492
Returns true if openstack-origin-git is specified.
494
return config('openstack-origin-git') is not None
476
497
requirements_dir = None
479
def git_clone_and_install(file_name, core_project):
480
"""Clone/install all OpenStack repos specified in yaml config file."""
500
def git_clone_and_install(projects_yaml, core_project):
502
Clone/install all specified OpenStack repositories.
504
The expected format of projects_yaml is:
507
repository: 'git://git.openstack.org/openstack/keystone.git',
508
branch: 'stable/icehouse'}
509
- {name: requirements,
510
repository: 'git://git.openstack.org/openstack/requirements.git',
511
branch: 'stable/icehouse'}
512
directory: /mnt/openstack-git
513
http_proxy: http://squid.internal:3128
514
https_proxy: https://squid.internal:3128
516
The directory, http_proxy, and https_proxy keys are optional.
481
518
global requirements_dir
519
parent_dir = '/mnt/openstack-git'
483
if file_name == "None":
521
if not projects_yaml:
486
yaml_file = os.path.join(charm_dir(), file_name)
488
# clone/install the requirements project first
489
installed = _git_clone_and_install_subset(yaml_file,
490
whitelist=['requirements'])
491
if 'requirements' not in installed:
492
error_out('requirements git repository must be specified')
494
# clone/install all other projects except requirements and the core project
495
blacklist = ['requirements', core_project]
496
_git_clone_and_install_subset(yaml_file, blacklist=blacklist,
497
update_requirements=True)
499
# clone/install the core project
500
whitelist = [core_project]
501
installed = _git_clone_and_install_subset(yaml_file, whitelist=whitelist,
502
update_requirements=True)
503
if core_project not in installed:
504
error_out('{} git repository must be specified'.format(core_project))
507
def _git_clone_and_install_subset(yaml_file, whitelist=[], blacklist=[],
508
update_requirements=False):
509
"""Clone/install subset of OpenStack repos specified in yaml config file."""
510
global requirements_dir
513
with open(yaml_file, 'r') as fd:
514
projects = yaml.load(fd)
515
for proj, val in projects.items():
516
# The project subset is chosen based on the following 3 rules:
517
# 1) If project is in blacklist, we don't clone/install it, period.
518
# 2) If whitelist is empty, we clone/install everything else.
519
# 3) If whitelist is not empty, we clone/install everything in the
521
if proj in blacklist:
523
if whitelist and proj not in whitelist:
525
repo = val['repository']
526
branch = val['branch']
527
repo_dir = _git_clone_and_install_single(repo, branch,
529
if proj == 'requirements':
530
requirements_dir = repo_dir
531
installed.append(proj)
535
def _git_clone_and_install_single(repo, branch, update_requirements=False):
536
"""Clone and install a single git repository."""
537
dest_parent_dir = "/mnt/openstack-git/"
538
dest_dir = os.path.join(dest_parent_dir, os.path.basename(repo))
540
if not os.path.exists(dest_parent_dir):
541
juju_log('Host dir not mounted at {}. '
542
'Creating directory there instead.'.format(dest_parent_dir))
543
os.mkdir(dest_parent_dir)
524
projects = yaml.load(projects_yaml)
525
_git_validate_projects_yaml(projects, core_project)
527
if 'http_proxy' in projects.keys():
528
os.environ['http_proxy'] = projects['http_proxy']
530
if 'https_proxy' in projects.keys():
531
os.environ['https_proxy'] = projects['https_proxy']
533
if 'directory' in projects.keys():
534
parent_dir = projects['directory']
536
for p in projects['repositories']:
537
repo = p['repository']
539
if p['name'] == 'requirements':
540
repo_dir = _git_clone_and_install_single(repo, branch, parent_dir,
541
update_requirements=False)
542
requirements_dir = repo_dir
544
repo_dir = _git_clone_and_install_single(repo, branch, parent_dir,
545
update_requirements=True)
548
def _git_validate_projects_yaml(projects, core_project):
550
Validate the projects yaml.
552
_git_ensure_key_exists('repositories', projects)
554
for project in projects['repositories']:
555
_git_ensure_key_exists('name', project.keys())
556
_git_ensure_key_exists('repository', project.keys())
557
_git_ensure_key_exists('branch', project.keys())
559
if projects['repositories'][0]['name'] != 'requirements':
560
error_out('{} git repo must be specified first'.format('requirements'))
562
if projects['repositories'][-1]['name'] != core_project:
563
error_out('{} git repo must be specified last'.format(core_project))
566
def _git_ensure_key_exists(key, keys):
568
Ensure that key exists in keys.
571
error_out('openstack-origin-git key \'{}\' is missing'.format(key))
574
def _git_clone_and_install_single(repo, branch, parent_dir, update_requirements):
576
Clone and install a single git repository.
578
dest_dir = os.path.join(parent_dir, os.path.basename(repo))
580
if not os.path.exists(parent_dir):
581
juju_log('Directory already exists at {}. '
582
'No need to create directory.'.format(parent_dir))
545
585
if not os.path.exists(dest_dir):
546
586
juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
547
repo_dir = install_remote(repo, dest=dest_parent_dir, branch=branch)
587
repo_dir = install_remote(repo, dest=parent_dir, branch=branch)
549
589
repo_dir = dest_dir
563
603
def _git_update_requirements(package_dir, reqs_dir):
564
"""Update from global requirements.
605
Update from global requirements.
566
Update an OpenStack git directory's requirements.txt and
567
test-requirements.txt from global-requirements.txt."""
607
Update an OpenStack git directory's requirements.txt and
608
test-requirements.txt from global-requirements.txt.
568
610
orig_dir = os.getcwd()
569
611
os.chdir(reqs_dir)
570
cmd = "python update.py {}".format(package_dir)
612
cmd = ['python', 'update.py', package_dir]
572
subprocess.check_call(cmd.split(' '))
614
subprocess.check_call(cmd)
573
615
except subprocess.CalledProcessError:
574
616
package = os.path.basename(package_dir)
575
617
error_out("Error updating {} from global-requirements.txt".format(package))
576
618
os.chdir(orig_dir)
621
def git_src_dir(projects_yaml, project):
623
Return the directory where the specified project's source is located.
625
parent_dir = '/mnt/openstack-git'
627
if not projects_yaml:
630
projects = yaml.load(projects_yaml)
632
if 'directory' in projects.keys():
633
parent_dir = projects['directory']
635
for p in projects['repositories']:
636
if p['name'] == project:
637
return os.path.join(parent_dir, os.path.basename(p['repository']))