56
from charmhelpers.contrib.python.packages import (
57
pip_create_virtualenv,
56
61
from charmhelpers.core.host import lsb_release, mounts, umount
57
62
from charmhelpers.fetch import apt_install, apt_cache, install_remote
58
from charmhelpers.contrib.python.packages import pip_install
59
63
from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk
60
64
from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device
317
324
'kilo': 'trusty-updates/kilo',
318
325
'kilo/updates': 'trusty-updates/kilo',
319
326
'kilo/proposed': 'trusty-proposed/kilo',
327
'liberty': 'trusty-updates/liberty',
328
'liberty/updates': 'trusty-updates/liberty',
329
'liberty/proposed': 'trusty-proposed/liberty',
497
507
requirements_dir = None
500
def git_clone_and_install(projects_yaml, core_project):
510
def _git_yaml_load(projects_yaml):
512
Load the specified yaml into a dictionary.
514
if not projects_yaml:
517
return yaml.load(projects_yaml)
520
def git_clone_and_install(projects_yaml, core_project, depth=1):
502
522
Clone/install all specified OpenStack repositories.
504
524
The expected format of projects_yaml is:
506
527
- {name: keystone,
507
528
repository: 'git://git.openstack.org/openstack/keystone.git',
509
530
- {name: requirements,
510
531
repository: 'git://git.openstack.org/openstack/requirements.git',
511
532
branch: 'stable/icehouse'}
512
534
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.
535
http_proxy: squid-proxy-url
536
https_proxy: squid-proxy-url
538
The directory, http_proxy, and https_proxy keys are optional.
518
541
global requirements_dir
519
542
parent_dir = '/mnt/openstack-git'
521
if not projects_yaml:
524
projects = yaml.load(projects_yaml)
545
projects = _git_yaml_load(projects_yaml)
525
546
_git_validate_projects_yaml(projects, core_project)
527
548
old_environ = dict(os.environ)
529
550
if 'http_proxy' in projects.keys():
551
http_proxy = projects['http_proxy']
530
552
os.environ['http_proxy'] = projects['http_proxy']
531
553
if 'https_proxy' in projects.keys():
532
554
os.environ['https_proxy'] = projects['https_proxy']
534
556
if 'directory' in projects.keys():
535
557
parent_dir = projects['directory']
559
pip_create_virtualenv(os.path.join(parent_dir, 'venv'))
561
# Upgrade setuptools and pip from default virtualenv versions. The default
562
# versions in trusty break master OpenStack branch deployments.
563
for p in ['pip', 'setuptools']:
564
pip_install(p, upgrade=True, proxy=http_proxy,
565
venv=os.path.join(parent_dir, 'venv'))
537
567
for p in projects['repositories']:
538
568
repo = p['repository']
539
569
branch = p['branch']
540
570
if p['name'] == 'requirements':
541
repo_dir = _git_clone_and_install_single(repo, branch, parent_dir,
571
repo_dir = _git_clone_and_install_single(repo, branch, depth,
572
parent_dir, http_proxy,
542
573
update_requirements=False)
543
574
requirements_dir = repo_dir
545
repo_dir = _git_clone_and_install_single(repo, branch, parent_dir,
576
repo_dir = _git_clone_and_install_single(repo, branch, depth,
577
parent_dir, http_proxy,
546
578
update_requirements=True)
548
580
os.environ = old_environ
574
606
error_out('openstack-origin-git key \'{}\' is missing'.format(key))
577
def _git_clone_and_install_single(repo, branch, parent_dir, update_requirements):
609
def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy,
610
update_requirements):
579
612
Clone and install a single git repository.
588
621
if not os.path.exists(dest_dir):
589
622
juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch))
590
repo_dir = install_remote(repo, dest=parent_dir, branch=branch)
623
repo_dir = install_remote(repo, dest=parent_dir, branch=branch,
592
626
repo_dir = dest_dir
628
venv = os.path.join(parent_dir, 'venv')
594
630
if update_requirements:
595
631
if not requirements_dir:
596
632
error_out('requirements repo must be cloned before '
597
633
'updating from global requirements.')
598
_git_update_requirements(repo_dir, requirements_dir)
634
_git_update_requirements(venv, repo_dir, requirements_dir)
600
636
juju_log('Installing git repo from dir: {}'.format(repo_dir))
601
pip_install(repo_dir)
638
pip_install(repo_dir, proxy=http_proxy, venv=venv)
640
pip_install(repo_dir, venv=venv)
606
def _git_update_requirements(package_dir, reqs_dir):
645
def _git_update_requirements(venv, package_dir, reqs_dir):
608
647
Update from global requirements.
613
652
orig_dir = os.getcwd()
614
653
os.chdir(reqs_dir)
615
cmd = ['python', 'update.py', package_dir]
654
python = os.path.join(venv, 'bin/python')
655
cmd = [python, 'update.py', package_dir]
617
657
subprocess.check_call(cmd)
618
658
except subprocess.CalledProcessError:
619
659
package = os.path.basename(package_dir)
620
error_out("Error updating {} from global-requirements.txt".format(package))
660
error_out("Error updating {} from "
661
"global-requirements.txt".format(package))
621
662
os.chdir(orig_dir)
665
def git_pip_venv_dir(projects_yaml):
667
Return the pip virtualenv path.
669
parent_dir = '/mnt/openstack-git'
671
projects = _git_yaml_load(projects_yaml)
673
if 'directory' in projects.keys():
674
parent_dir = projects['directory']
676
return os.path.join(parent_dir, 'venv')
624
679
def git_src_dir(projects_yaml, project):
626
681
Return the directory where the specified project's source is located.
628
683
parent_dir = '/mnt/openstack-git'
630
if not projects_yaml:
633
projects = yaml.load(projects_yaml)
685
projects = _git_yaml_load(projects_yaml)
635
687
if 'directory' in projects.keys():
636
688
parent_dir = projects['directory']
640
692
return os.path.join(parent_dir, os.path.basename(p['repository']))
697
def git_yaml_value(projects_yaml, key):
699
Return the value in projects_yaml for the specified key.
701
projects = _git_yaml_load(projects_yaml)
703
if key in projects.keys():