def test_write_config(self):
        cfg_path = self.write_config(os.path.join(self.work_dir,
            'ooinstall.conf'), SAMPLE_CONFIG)
        ooconfig = OOConfig(cfg_path)
        ooconfig.save_to_disk()

        f = open(cfg_path, 'r')
        written_config = yaml.safe_load(f.read())
        f.close()



        self.assertEquals(3, len(written_config['deployment']['hosts']))
        for h in written_config['deployment']['hosts']:
            self.assertTrue('ip' in h)
            self.assertTrue('public_ip' in h)
            self.assertTrue('hostname' in h)
            self.assertTrue('public_hostname' in h)

        self.assertTrue('ansible_ssh_user' in written_config['deployment'])
        self.assertTrue('variant' in written_config)
        self.assertEquals('v2', written_config['version'])

        # Some advanced settings should not get written out if they
        # were not specified by the user:
        self.assertFalse('ansible_inventory_directory' in written_config)
Example #2
0
    def test_write_config(self):
        cfg_path = self.write_config(os.path.join(self.work_dir,
            'ooinstall.conf'), SAMPLE_CONFIG)
        ooconfig = OOConfig(cfg_path)
        ooconfig.save_to_disk()

        f = open(cfg_path, 'r')
        written_config = yaml.safe_load(f.read())
        f.close()



        self.assertEquals(3, len(written_config['deployment']['hosts']))
        for h in written_config['deployment']['hosts']:
            self.assertTrue('ip' in h)
            self.assertTrue('public_ip' in h)
            self.assertTrue('hostname' in h)
            self.assertTrue('public_hostname' in h)

        self.assertTrue('ansible_ssh_user' in written_config['deployment'])
        self.assertTrue('variant' in written_config)
        self.assertEquals('v2', written_config['version'])

        # Some advanced settings should not get written out if they
        # were not specified by the user:
        self.assertFalse('ansible_inventory_directory' in written_config)
 def test_load_host_incomplete_facts(self):
     cfg_path = self.write_config(os.path.join(self.work_dir, "ooinstall.conf"), CONFIG_INCOMPLETE_FACTS)
     ooconfig = OOConfig(cfg_path)
     missing_host_facts = ooconfig.calc_missing_facts()
     self.assertEquals(2, len(missing_host_facts))
     self.assertEquals(1, len(missing_host_facts["10.0.0.2"]))
     self.assertEquals(3, len(missing_host_facts["10.0.0.3"]))
Example #4
0
 def test_load_host_incomplete_facts(self):
     cfg_path = self.write_config(os.path.join(self.work_dir,
         'ooinstall.conf'), CONFIG_INCOMPLETE_FACTS)
     ooconfig = OOConfig(cfg_path)
     missing_host_facts = ooconfig.calc_missing_facts()
     self.assertEquals(2, len(missing_host_facts))
     self.assertEquals(1, len(missing_host_facts['10.0.0.2']))
     self.assertEquals(3, len(missing_host_facts['10.0.0.3']))
 def setUp(self):
     self.tempfiles = []
     self.work_dir = tempfile.mkdtemp(prefix='openshift_ansible_tests')
     self.configfile = os.path.join(self.work_dir, 'ooinstall.config')
     with open(self.configfile, 'w') as config_file:
         config_file.write(BASE_CONFIG)
     self.inventory = os.path.join(self.work_dir, 'hosts')
     config = OOConfig(self.configfile)
     config.settings['ansible_inventory_path'] = self.inventory
     openshift_ansible.set_config(config)
Example #6
0
 def setUp(self):
     self.tempfiles = []
     self.work_dir = tempfile.mkdtemp(prefix='openshift_ansible_tests')
     self.configfile = os.path.join(self.work_dir, 'ooinstall.config')
     with open(self.configfile, 'w') as config_file:
         config_file.write(BASE_CONFIG)
     self.inventory = os.path.join(self.work_dir, 'hosts')
     config = OOConfig(self.configfile)
     config.settings['ansible_inventory_path'] = self.inventory
     openshift_ansible.set_config(config)
    def test_load_bad_config(self):

        cfg_path = self.write_config(
            os.path.join(self.work_dir, 'ooinstall.conf'), CONFIG_BAD)
        try:
            OOConfig(cfg_path)
            assert False
        except OOConfigInvalidHostError:
            assert True
Example #8
0
class LegacyOOConfigTests(OOInstallFixture):

    def setUp(self):
        OOInstallFixture.setUp(self)
        self.cfg_path = self.write_config(os.path.join(self.work_dir,
            'ooinstall.conf'), LEGACY_CONFIG)
        self.cfg = OOConfig(self.cfg_path)

    def test_load_config_memory(self):
        self.assertEquals('openshift-enterprise', self.cfg.settings['variant'])
        self.assertEquals('3.0', self.cfg.settings['variant_version'])
        self.assertEquals('v1', self.cfg.settings['version'])

        self.assertEquals(3, len(self.cfg.hosts))
        h1 = self.cfg.get_host('10.0.0.1')
        self.assertEquals('10.0.0.1', h1.ip)
        self.assertEquals('24.222.0.1', h1.public_ip)
        self.assertEquals('master-private.example.com', h1.hostname)
        self.assertEquals('master.example.com', h1.public_hostname)

        h2 = self.cfg.get_host('10.0.0.2')
        self.assertEquals('10.0.0.2', h2.ip)
        self.assertEquals('24.222.0.2', h2.public_ip)
        self.assertEquals('node1-private.example.com', h2.hostname)
        self.assertEquals('node1.example.com', h2.public_hostname)

        h3 = self.cfg.get_host('10.0.0.3')
        self.assertEquals('10.0.0.3', h3.ip)
        self.assertEquals('24.222.0.3', h3.public_ip)
        self.assertEquals('node2-private.example.com', h3.hostname)
        self.assertEquals('node2.example.com', h3.public_hostname)

        self.assertFalse('masters' in self.cfg.settings)
        self.assertFalse('nodes' in self.cfg.settings)
        self.assertFalse('Description' in self.cfg.settings)
        self.assertFalse('Name' in self.cfg.settings)
        self.assertFalse('Subscription' in self.cfg.settings)
        self.assertFalse('Vendor' in self.cfg.settings)
        self.assertFalse('Version' in self.cfg.settings)
        self.assertFalse('validates_facts' in self.cfg.settings)
class LegacyOOConfigTests(OOInstallFixture):

    def setUp(self):
        OOInstallFixture.setUp(self)
        self.cfg_path = self.write_config(os.path.join(self.work_dir,
            'ooinstall.conf'), LEGACY_CONFIG)
        self.cfg = OOConfig(self.cfg_path)

    def test_load_config_memory(self):
        self.assertEquals('openshift-enterprise', self.cfg.settings['variant'])
        self.assertEquals('3.0', self.cfg.settings['variant_version'])
        self.assertEquals('v1', self.cfg.settings['version'])

        self.assertEquals(3, len(self.cfg.hosts))
        h1 = self.cfg.get_host('10.0.0.1')
        self.assertEquals('10.0.0.1', h1.ip)
        self.assertEquals('24.222.0.1', h1.public_ip)
        self.assertEquals('master-private.example.com', h1.hostname)
        self.assertEquals('master.example.com', h1.public_hostname)

        h2 = self.cfg.get_host('10.0.0.2')
        self.assertEquals('10.0.0.2', h2.ip)
        self.assertEquals('24.222.0.2', h2.public_ip)
        self.assertEquals('node1-private.example.com', h2.hostname)
        self.assertEquals('node1.example.com', h2.public_hostname)

        h3 = self.cfg.get_host('10.0.0.3')
        self.assertEquals('10.0.0.3', h3.ip)
        self.assertEquals('24.222.0.3', h3.public_ip)
        self.assertEquals('node2-private.example.com', h3.hostname)
        self.assertEquals('node2.example.com', h3.public_hostname)

        self.assertFalse('masters' in self.cfg.settings)
        self.assertFalse('nodes' in self.cfg.settings)
        self.assertFalse('Description' in self.cfg.settings)
        self.assertFalse('Name' in self.cfg.settings)
        self.assertFalse('Subscription' in self.cfg.settings)
        self.assertFalse('Vendor' in self.cfg.settings)
        self.assertFalse('Version' in self.cfg.settings)
        self.assertFalse('validates_facts' in self.cfg.settings)
class LegacyOOConfigTests(OOInstallFixture):
    def setUp(self):
        OOInstallFixture.setUp(self)
        self.cfg_path = self.write_config(os.path.join(self.work_dir, "ooinstall.conf"), LEGACY_CONFIG)
        self.cfg = OOConfig(self.cfg_path)

    def test_load_config_memory(self):
        self.assertEquals("openshift-enterprise", self.cfg.settings["variant"])
        self.assertEquals("3.0", self.cfg.settings["variant_version"])
        self.assertEquals("v1", self.cfg.settings["version"])

        self.assertEquals(3, len(self.cfg.hosts))
        h1 = self.cfg.get_host("10.0.0.1")
        self.assertEquals("10.0.0.1", h1.ip)
        self.assertEquals("24.222.0.1", h1.public_ip)
        self.assertEquals("master-private.example.com", h1.hostname)
        self.assertEquals("master.example.com", h1.public_hostname)

        h2 = self.cfg.get_host("10.0.0.2")
        self.assertEquals("10.0.0.2", h2.ip)
        self.assertEquals("24.222.0.2", h2.public_ip)
        self.assertEquals("node1-private.example.com", h2.hostname)
        self.assertEquals("node1.example.com", h2.public_hostname)

        h3 = self.cfg.get_host("10.0.0.3")
        self.assertEquals("10.0.0.3", h3.ip)
        self.assertEquals("24.222.0.3", h3.public_ip)
        self.assertEquals("node2-private.example.com", h3.hostname)
        self.assertEquals("node2.example.com", h3.public_hostname)

        self.assertFalse("masters" in self.cfg.settings)
        self.assertFalse("nodes" in self.cfg.settings)
        self.assertFalse("Description" in self.cfg.settings)
        self.assertFalse("Name" in self.cfg.settings)
        self.assertFalse("Subscription" in self.cfg.settings)
        self.assertFalse("Vendor" in self.cfg.settings)
        self.assertFalse("Version" in self.cfg.settings)
        self.assertFalse("validates_facts" in self.cfg.settings)
def cli(ctx, unattended, configuration, ansible_playbook_directory,
        ansible_config, ansible_log_path, verbose, debug):
    """
    atomic-openshift-installer makes the process for installing OSE or AEP
    easier by interactively gathering the data needed to run on each host.
    It can also be run in unattended mode if provided with a configuration file.

    Further reading: https://docs.openshift.com/enterprise/latest/install_config/install/quick_install.html
    """
    if debug:
        # DEFAULT log level threshold is set to CRITICAL (the
        # highest), anything below that (we only use debug/warning
        # presently) is not logged. If '-d' is given though, we'll
        # lower the threshold to debug (almost everything gets through)
        installer_log.setLevel(logging.DEBUG)
        installer_log.debug("Quick Installer debugging initialized")

    ctx.obj = {}
    ctx.obj['unattended'] = unattended
    ctx.obj['configuration'] = configuration
    ctx.obj['ansible_config'] = ansible_config
    ctx.obj['ansible_log_path'] = ansible_log_path
    ctx.obj['verbose'] = verbose

    try:
        oo_cfg = OOConfig(ctx.obj['configuration'])
    except OOConfigInvalidHostError as e:
        click.echo(e)
        sys.exit(1)

    # If no playbook dir on the CLI, check the config:
    if not ansible_playbook_directory:
        ansible_playbook_directory = oo_cfg.settings.get(
            'ansible_playbook_directory', '')
    # If still no playbook dir, check for the default location:
    if not ansible_playbook_directory and os.path.exists(DEFAULT_PLAYBOOK_DIR):
        ansible_playbook_directory = DEFAULT_PLAYBOOK_DIR
    validate_ansible_dir(ansible_playbook_directory)
    oo_cfg.settings['ansible_playbook_directory'] = ansible_playbook_directory
    oo_cfg.ansible_playbook_directory = ansible_playbook_directory
    ctx.obj['ansible_playbook_directory'] = ansible_playbook_directory

    if ctx.obj['ansible_config']:
        oo_cfg.settings['ansible_config'] = ctx.obj['ansible_config']
    elif 'ansible_config' not in oo_cfg.settings and \
         os.path.exists(DEFAULT_ANSIBLE_CONFIG):
        # If we're installed by RPM this file should exist and we can use it as our default:
        oo_cfg.settings['ansible_config'] = DEFAULT_ANSIBLE_CONFIG

    oo_cfg.settings['ansible_log_path'] = ctx.obj['ansible_log_path']

    ctx.obj['oo_cfg'] = oo_cfg
    openshift_ansible.set_config(oo_cfg)
    def test_write_config(self):
        cfg_path = self.write_config(os.path.join(self.work_dir, "ooinstall.conf"), SAMPLE_CONFIG)
        ooconfig = OOConfig(cfg_path)
        ooconfig.save_to_disk()

        f = open(cfg_path, "r")
        written_config = yaml.safe_load(f.read())
        f.close()

        self.assertEquals(3, len(written_config["hosts"]))
        for h in written_config["hosts"]:
            self.assertTrue("ip" in h)
            self.assertTrue("public_ip" in h)
            self.assertTrue("hostname" in h)
            self.assertTrue("public_hostname" in h)

        self.assertTrue("ansible_ssh_user" in written_config)
        self.assertTrue("variant" in written_config)
        self.assertEquals("v1", written_config["version"])

        # Some advanced settings should not get written out if they
        # were not specified by the user:
        self.assertFalse("ansible_inventory_directory" in written_config)
    def test_load_config(self):

        cfg_path = self.write_config(
            os.path.join(self.work_dir, 'ooinstall.conf'), SAMPLE_CONFIG)
        ooconfig = OOConfig(cfg_path)

        self.assertEquals(3, len(ooconfig.hosts))
        self.assertEquals("10.0.0.1", ooconfig.hosts[0].name)
        self.assertEquals("10.0.0.1", ooconfig.hosts[0].ip)
        self.assertEquals("master-private.example.com",
                          ooconfig.hosts[0].hostname)

        self.assertEquals(["10.0.0.1", "10.0.0.2", "10.0.0.3"],
                          [host['ip'] for host in ooconfig.settings['hosts']])

        self.assertEquals('openshift-enterprise', ooconfig.settings['variant'])
def cli(ctx, unattended, configuration, ansible_playbook_directory, ansible_config, ansible_log_path, verbose, debug):
    """
    atomic-openshift-installer makes the process for installing OSE or AEP
    easier by interactively gathering the data needed to run on each host.
    It can also be run in unattended mode if provided with a configuration file.

    Further reading: https://docs.openshift.com/enterprise/latest/install_config/install/quick_install.html
    """
    if debug:
        # DEFAULT log level threshold is set to CRITICAL (the
        # highest), anything below that (we only use debug/warning
        # presently) is not logged. If '-d' is given though, we'll
        # lower the threshold to debug (almost everything gets through)
        installer_log.setLevel(logging.DEBUG)
        installer_log.debug("Quick Installer debugging initialized")

    ctx.obj = {}
    ctx.obj['unattended'] = unattended
    ctx.obj['configuration'] = configuration
    ctx.obj['ansible_config'] = ansible_config
    ctx.obj['ansible_log_path'] = ansible_log_path
    ctx.obj['verbose'] = verbose

    try:
        oo_cfg = OOConfig(ctx.obj['configuration'])
    except OOConfigInvalidHostError as e:
        click.echo(e)
        sys.exit(1)

    # If no playbook dir on the CLI, check the config:
    if not ansible_playbook_directory:
        ansible_playbook_directory = oo_cfg.settings.get('ansible_playbook_directory', '')
    # If still no playbook dir, check for the default location:
    if not ansible_playbook_directory and os.path.exists(DEFAULT_PLAYBOOK_DIR):
        ansible_playbook_directory = DEFAULT_PLAYBOOK_DIR
    validate_ansible_dir(ansible_playbook_directory)
    oo_cfg.settings['ansible_playbook_directory'] = ansible_playbook_directory
    oo_cfg.ansible_playbook_directory = ansible_playbook_directory
    ctx.obj['ansible_playbook_directory'] = ansible_playbook_directory

    if ctx.obj['ansible_config']:
        oo_cfg.settings['ansible_config'] = ctx.obj['ansible_config']
    elif 'ansible_config' not in oo_cfg.settings and \
         os.path.exists(DEFAULT_ANSIBLE_CONFIG):
        # If we're installed by RPM this file should exist and we can use it as our default:
        oo_cfg.settings['ansible_config'] = DEFAULT_ANSIBLE_CONFIG

    oo_cfg.settings['ansible_log_path'] = ctx.obj['ansible_log_path']

    ctx.obj['oo_cfg'] = oo_cfg
    openshift_ansible.set_config(oo_cfg)
Example #15
0
 def setUp(self):
     OOInstallFixture.setUp(self)
     self.cfg_path = self.write_config(os.path.join(self.work_dir,
         'ooinstall.conf'), LEGACY_CONFIG)
     self.cfg = OOConfig(self.cfg_path)
 def test_load_complete_facts(self):
     cfg_path = self.write_config(os.path.join(self.work_dir,
         'ooinstall.conf'), SAMPLE_CONFIG)
     ooconfig = OOConfig(cfg_path)
     missing_host_facts = ooconfig.calc_missing_facts()
     self.assertEquals(0, len(missing_host_facts))
 def test_load_complete_facts(self):
     cfg_path = self.write_config(
         os.path.join(self.work_dir, 'ooinstall.conf'), SAMPLE_CONFIG)
     ooconfig = OOConfig(cfg_path)
     missing_host_facts = ooconfig.calc_missing_facts()
     self.assertEquals(0, len(missing_host_facts))
 def setUp(self):
     OOInstallFixture.setUp(self)
     self.cfg_path = self.write_config(os.path.join(self.work_dir, "ooinstall.conf"), LEGACY_CONFIG)
     self.cfg = OOConfig(self.cfg_path)