def test_charmconfig_custom_overwrite(self, mockspew): """ Verify complex yaml can safely overwrite existing defined keys """ charm_conf = yaml.load(slurp(os.path.join(DATA_DIR, 'charmconf.yaml'))) charm_conf_custom = yaml.load( slurp(os.path.join(DATA_DIR, 'charmconf-deepchainmap-fail.yaml'))) merged_dicts = merge_dicts(charm_conf, charm_conf_custom) with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf: spew(tempf.name, yaml.safe_dump(merged_dicts, default_flow_style=False)) modified_charm_conf = yaml.load(slurp(tempf.name)) self.assertEqual(modified_charm_conf['mysql']['dataset-size'], '512M') self.assertEqual(modified_charm_conf['swift-storage']['zone'], 1)
def test_charmconfig_custom_overwrite(self, mockspew): """ Verify complex yaml can safely overwrite existing defined keys """ charm_conf = yaml.load(slurp(os.path.join(DATA_DIR, 'charmconf.yaml'))) charm_conf_custom = yaml.load(slurp( os.path.join(DATA_DIR, 'charmconf-deepchainmap-fail.yaml'))) merged_dicts = merge_dicts(charm_conf, charm_conf_custom) with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf: spew(tempf.name, yaml.safe_dump( merged_dicts, default_flow_style=False)) modified_charm_conf = yaml.load(slurp(tempf.name)) self.assertEqual(modified_charm_conf['mysql']['dataset-size'], '512M') self.assertEqual(modified_charm_conf['swift-storage']['zone'], 1)
class TestSingle: USERDIR = os.path.expanduser("~/.cloud-install") CONFIG = yaml.load(utils.slurp(os.path.join(USERDIR, 'config.yaml'))) def test_openstack_creds_exist(self): """ Verifies OpenStack credential files exist """ creds = ['openstack-admin-rc', 'openstack-ubuntu-rc'] for c in creds: assert os.path.isfile(os.path.join(self.USERDIR, c)) def test_bootstrap_succeeded(self): """ Verifies a local bootstrap happened """ cmd = ("JUJU_HOME=~/.cloud-install/juju juju stat --format yaml") out = Container.run(self.CONFIG['container_name'], cmd, use_ssh=True) out = out.split("\n")[0].strip() assert ('environment: local' in out) def test_container_ip_matches(self): """ Verifies container ip in config matches what LXC sees """ saved_ip = self.CONFIG['container_ip'] lxc_ip = Container.ip(self.CONFIG['container_name']) assert saved_ip == lxc_ip
def cloud_init_finished(self): """checks cloud-init result.json in container to find out status returns True if cloud-init finished with no errors, False if it's not done yet, and raises an exception if it had errors. """ result_json = os.path.join(self.container_abspath, 'rootfs/var/lib/cloud/data/result.json') if not os.path.isfile(result_json): return False result_json = utils.slurp(result_json) log.debug("Cloud-init finished: {}".format(result_json)) if result_json == '': return False ret = json.loads(result_json) errors = ret['v1']['errors'] if len(errors): log.error("Container cloud-init finished with " "errors: {}".format(errors)) # FIXME: Log errors for now, don't be fatal as the main # error is coming from a pollinate command unable # to run which doesn't seem to effect the installer. # raise Exception("Container cloud-init returned errors") return True
def openstack_password(self): PASSWORD_FILE = os.path.join(self.cfg_path, 'openstack.passwd') try: _password = utils.slurp(PASSWORD_FILE) except IOError: _password = '******' return _password
class TestSingle: USERDIR = os.path.expanduser("~/.cloud-install") CONFIG = yaml.load(utils.slurp(os.path.join(USERDIR, 'config.yaml'))) def test_openstack_creds_exist(self): """ Verifies OpenStack credential files exist """ creds = ['openstack-admin-rc', 'openstack-ubuntu-rc'] for c in creds: assert os.path.isfile(os.path.join(self.USERDIR, c)) def test_bootstrap_succeeded(self): """ Verifies a local bootstrap happened """ cmd = ("openstack-juju stat --format yaml") out = utils.get_command_output(cmd) out = out['output'] assert ('environment: local' in out) def test_config_deploy_complete(self): """ Verifies config data: deploy is complete. """ assert self.CONFIG['deploy_complete'] is True def test_config_postproc_complete(self): """ Verifies config data: postproc is complete. """ assert self.CONFIG['postproc_complete'] is True def test_config_relations_complete(self): """ Verifies config data: relations are complete. """ assert self.CONFIG['relations_complete'] is True
def openstack_password(self): PASSWORD_FILE = os.path.join(self.cfg_path, 'openstack.passwd') try: _password = utils.slurp(PASSWORD_FILE) except IOError: log.exception('exception loading openstack password') raise ConfigException('cannot load saved openstack password') return _password
def maas_creds(self): """ reads maascreds file """ MAAS_CREDS_FILE = os.path.join(self.cfg_path, 'maascreds') try: _maascreds = json.loads(utils.slurp(MAAS_CREDS_FILE)) except IOError: _maascreds = dict() return _maascreds
def landscape_creds(self): """ reads landscape creds file """ LANDSCAPE_CREDS_FILE = os.path.join(self.cfg_path, 'landscapecreds') try: _creds = json.loads(utils.slurp(LANDSCAPE_CREDS_FILE)) except IOError: _creds = dict() return _creds
def _is_auth_url_valid(self): existing_yaml = yaml.load(slurp(self.config.juju_environments_path)) existing_yaml = existing_yaml["environments"] if "openstack" in existing_yaml: if "http://keystoneurl" in existing_yaml["openstack"]["auth-url"]: return False else: log.debug("Found an existing keystone auth-url, skipping.") return True return False
def _is_auth_url_valid(self): existing_yaml = yaml.load(slurp(self.config.juju_environments_path)) existing_yaml = existing_yaml['environments'] if 'openstack' in existing_yaml: if 'http://keystoneurl' in existing_yaml['openstack']['auth-url']: return False else: log.debug("Found an existing keystone auth-url, skipping.") return True return False
def landscape_creds(self): """ reads landscape creds file """ LANDSCAPE_CREDS_FILE = os.path.join(self.cfg_path, 'landscapecreds') try: _creds = json.loads(utils.slurp(LANDSCAPE_CREDS_FILE)) except IOError: log.exception("exception loading lanscape creds") raise ConfigException("cannot load landscape creds") return _creds
def maas_creds(self): """ reads maascreds file """ MAAS_CREDS_FILE = os.path.join(self.cfg_path, 'maascreds') try: _maascreds = json.loads(utils.slurp(MAAS_CREDS_FILE)) except IOError: log.exception('exception loading maas creds') raise ConfigException("cannot load saved maas creds") return _maascreds
def test_charmconfig_custom_merge(self, mockspew): """ Verify rightmost custom charm config dictionary does not overwrite untouched items in rendered charmconfig """ charm_custom = {"swift-proxy": {"replicas": 15}, "mysql": {"dataset-size": "2048M"}} charm_conf = yaml.load(slurp(os.path.join(DATA_DIR, "charmconf.yaml"))) merged_dicts = merge_dicts(charm_conf, charm_custom) self.assertEqual(merged_dicts["mysql"]["max-connections"], 25000) self.assertEqual(merged_dicts["swift-proxy"]["zone-assignment"], "auto")
def test_charmconfig_custom_merge(self, mockspew): """ Verify rightmost custom charm config dictionary does not overwrite untouched items in rendered charmconfig """ charm_custom = {'swift-proxy': {'replicas': 15}, 'mysql': {'dataset-size': '2048M'}} charm_conf = yaml.load(slurp(os.path.join(DATA_DIR, 'charmconf.yaml'))) merged_dicts = merge_dicts(charm_conf, charm_custom) self.assertEqual(merged_dicts['mysql']['max-connections'], 25000) self.assertEqual(merged_dicts['swift-proxy']['zone-assignment'], 'auto')
def run_deployer(self): # Prep deployer template for landscape lscape_password = utils.random_password() password_re = re.compile('(change-me)') lscape_env = utils.slurp(self.lscape_yaml_path) lscape_env_re = password_re.sub(lscape_password, str(lscape_env)) lscape_env_modified = { 'landscape-dense-maas': yaml.load(lscape_env_re) } utils.spew(self.lscape_yaml_path, yaml.dump(lscape_env_modified)) out = utils.get_command_output("{0} juju-deployer -WdvL -w 180 -c {1} " "landscape-dense-maas".format( self.config.juju_home(), self.lscape_yaml_path), timeout=None, user_sudo=True) if out['status']: log.error("Problem deploying Landscape: {}".format(out)) raise Exception("Error deploying Landscape.")
class TestMulti: USERDIR = os.path.expanduser("~/.cloud-install") CONFIG = yaml.load(utils.slurp(os.path.join(USERDIR, 'config.yaml'))) def test_openstack_creds_exist(self): """ Verifies OpenStack credential files exist. """ creds = ['openstack-admin-rc', 'openstack-ubuntu-rc'] for c in creds: assert os.path.isfile(os.path.join(self.USERDIR, c)) def todo_test_openstack_creds_admin_password(self): """ Verifies OpenStack admin password from config yaml matches admin password in admin rc file. """ # NOTE(beisner): revisit after https://goo.gl/dPPYcV # is resolved. pass def test_config_deploy_complete(self): """ Verifies config data: deploy is complete. """ assert self.CONFIG['deploy_complete'] is True def test_config_postproc_complete(self): """ Verifies config data: postproc is complete. """ assert self.CONFIG['postproc_complete'] is True def test_config_relations_complete(self): """ Verifies config data: relations are complete. """ assert self.CONFIG['relations_complete'] is True def test_juju_stat_enviro_name(self): """ Verifies juju stat and enviro name """ cmd = ("JUJU_HOME=~/.cloud-install/juju juju stat --format yaml") out = utils.get_command_output(cmd) assert ('environment: maas' in out['output'])
def run_deployer(self): # Prep deployer template for landscape lscape_password = utils.random_password() password_re = re.compile( '(change-me)') lscape_env = utils.slurp(self.lscape_yaml_path) lscape_env_re = password_re.sub( lscape_password, str(lscape_env)) lscape_env_modified = {'landscape-dense-maas': yaml.load( lscape_env_re)} utils.spew(self.lscape_yaml_path, yaml.dump(lscape_env_modified)) out = utils.get_command_output( "{0} juju-deployer -WdvL -w 180 -c {1} " "landscape-dense-maas".format( self.config.juju_home(), self.lscape_yaml_path), timeout=None, user_sudo=True) if out['status']: log.error("Problem deploying Landscape: {}".format(out)) raise Exception("Error deploying Landscape.")
import logging import unittest import yaml import os.path as path import argparse from tempfile import NamedTemporaryFile from cloudinstall.config import Config import cloudinstall.utils as utils log = logging.getLogger('cloudinstall.test_config') USER_DIR = path.expanduser('~') DATA_DIR = path.join(path.dirname(__file__), 'files') GOOD_CONFIG = yaml.load(utils.slurp(path.join(DATA_DIR, 'good_config.yaml'))) BAD_CONFIG = yaml.load(utils.slurp(path.join(DATA_DIR, 'bad_config.yaml'))) def parse_opts(argv): parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) parser.add_argument('-i', '--install-only', action='store_true', dest='install_only') parser.add_argument('-u', '--uninstall', action='store_true', dest='uninstall') parser.add_argument('-c', '--config', type=str, dest='config_file') parser.add_argument('-k', '--killcloud', action='store_true', dest='killcloud') parser.add_argument('--killcloud-noprompt', action='store_true', dest='killcloud_noprompt') parser.add_argument('--openstack-release', default=None,
# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import pytest import yaml import requests from os import path sys.path.insert(0, '/usr/share/openstack') from cloudinstall.config import Config # noqa from cloudinstall.juju import JujuState # noqa from macumba.v1 import JujuClient # noqa import cloudinstall.utils as utils # noqa CONFIGFILE = path.expanduser("~/.cloud-install/config.yaml") CONFIGOBJ = yaml.load(utils.slurp(CONFIGFILE)) @pytest.fixture def juju_state(): cfg = Config(CONFIGOBJ) uuid = cfg.juju_env['environ-uuid'] if not len(cfg.juju_env['state-servers']) > 0: state_server = 'localhost:17070' else: state_server = cfg.juju_env['state-servers'][0] url = path.join('wss://', state_server, 'environment', uuid, 'api') juju = JujuClient(url=url, password=cfg.juju_api_password) juju.login() return JujuState(juju)
# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import pytest import yaml import requests from os import path sys.path.insert(0, '/usr/share/openstack') from cloudinstall.config import Config from cloudinstall.juju import JujuState from macumba import JujuClient import cloudinstall.utils as utils CONFIGFILE = path.expanduser("~/.cloud-install/config.yaml") CONFIGOBJ = yaml.load(utils.slurp(CONFIGFILE)) @pytest.fixture def juju_state(): cfg = Config(CONFIGOBJ) if not len(cfg.juju_env['state-servers']) > 0: state_server = 'localhost:17070' else: state_server = cfg.juju_env['state-servers'][0] juju = JujuClient( url=path.join('wss://', state_server), password=cfg.juju_api_password) juju.login() return JujuState(juju)
import logging import unittest import yaml import os.path as path import argparse from tempfile import NamedTemporaryFile from cloudinstall.config import Config import cloudinstall.utils as utils log = logging.getLogger('cloudinstall.test_config') USER_DIR = path.expanduser('~') DATA_DIR = path.join(path.dirname(__file__), 'files') GOOD_CONFIG = yaml.load(utils.slurp(path.join(DATA_DIR, 'good_config.yaml'))) BAD_CONFIG = yaml.load(utils.slurp(path.join(DATA_DIR, 'bad_config.yaml'))) def parse_opts(argv): parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) parser.add_argument('-i', '--install-only', action='store_true', dest='install_only') parser.add_argument('-u', '--uninstall', action='store_true', dest='uninstall') parser.add_argument('-c', '--config', type=str, dest='config_file') parser.add_argument('-k',