Esempio n. 1
0
def get_db_credentials(shared_services, from_release):
    """
    Returns the database credentials using the provided shared services.
    """
    db_credential_keys = \
        {'barbican': {'hiera_user_key': 'barbican::db::postgresql::user',
                      'keyring_password_key': 'barbican',
                      },
         'sysinv': {'hiera_user_key': 'sysinv::db::postgresql::user',
                    'keyring_password_key': 'sysinv',
                    },
         }

    if sysinv_constants.SERVICE_TYPE_IDENTITY not in shared_services:
        db_credential_keys.update(
            {'keystone': {'hiera_user_key':
                          'keystone::db::postgresql::user',
                          'keyring_password_key': 'keystone',
                          }})

    # Get the hiera data for the from release
    hiera_path = os.path.join(PLATFORM_PATH, "puppet", from_release,
                              "hieradata")
    static_file = os.path.join(hiera_path, "static.yaml")
    with open(static_file, 'r') as file:
        static_config = yaml.load(file)

    db_credentials = dict()
    for database, values in db_credential_keys.items():
        username = static_config[values['hiera_user_key']]
        password = utils.get_password_from_keyring(
            values['keyring_password_key'], "database")
        db_credentials[database] = {'username': username, 'password': password}

    return db_credentials
Esempio n. 2
0
def migrate_sysinv_data(from_release, to_release):
    """ Migrates sysinv data. """
    devnull = open(os.devnull, 'w')

    LOG.info("Migrating sysinv data")

    # If the /opt/platform/sysinv/<release>/sysinv.conf.default file has
    # changed between releases it must be modified at this point.
    try:
        subprocess.check_call(
            ["cp",
             "-R",
             "--preserve",
             os.path.join(PLATFORM_PATH, "sysinv", from_release),
             os.path.join(PLATFORM_PATH, "sysinv", to_release)],
            stdout=devnull)

    except subprocess.CalledProcessError:
        LOG.exception("Failed to copy sysinv platform dir to new version")
        raise

    # Get the hiera data for the from release
    hiera_path = os.path.join(PLATFORM_PATH, "puppet", from_release,
                              "hieradata")
    static_file = os.path.join(hiera_path, "static.yaml")
    with open(static_file, 'r') as file:
        static_config = yaml.load(file)

    username = static_config["sysinv::db::postgresql::user"]
    password = utils.get_password_from_keyring("sysinv", "database")

    # We need a bare bones /etc/sysinv/sysinv.conf file in order to do the
    # sysinv database migration and then generate the upgrades manifests.
    with open("/etc/sysinv/sysinv.conf", "w") as f:
        f.write("[DEFAULT]\n")
        f.write("logging_context_format_string=sysinv %(asctime)s.%"
                "(msecs)03d %(process)d %(levelname)s %"
                "(name)s [%(request_id)s %(user)s %"
                "(tenant)s] %(instance)s%(message)s\n")
        f.write("verbose=True\n")
        f.write("syslog_log_facility=local6\n")
        f.write("use_syslog=True\n")
        f.write("logging_default_format_string=sysinv %(asctime)s.%"
                "(msecs)03d %(process)d %(levelname)s %(name)s [-] %"
                "(instance)s%(message)s\n")
        f.write("debug=False\n")
        f.write('sql_connection=postgresql://%s:%[email protected]/%s\n' %
                (username, password, 'sysinv'))
Esempio n. 3
0
def migrate_hiera_data(from_release, to_release, role=None):
    """ Migrate hiera data. """

    LOG.info("Migrating hiera data")
    from_hiera_path = os.path.join(PLATFORM_PATH, "puppet", from_release,
                                   "hieradata")
    to_hiera_path = constants.HIERADATA_PERMDIR

    # For simplex upgrade, we already set etcd security config during
    # apply-bootstrap-manifest. Need to get it and update to target
    # static.yaml.
    static_file = os.path.join(to_hiera_path, "static.yaml")
    etcd_security_config = {}

    if os.path.exists(static_file):
        with open(static_file, 'r') as yaml_file:
            static_config = yaml.load(yaml_file)

        if 'platform::etcd::params::security_enabled' in static_config.keys():
            etcd_security_config['platform::etcd::params::security_enabled'] = \
                static_config['platform::etcd::params::security_enabled']
            etcd_security_config['platform::etcd::params::bind_address'] = \
                static_config['platform::etcd::params::bind_address']
            etcd_security_config['platform::etcd::params::bind_address_version'] = \
                static_config['platform::etcd::params::bind_address_version']

    shutil.rmtree(to_hiera_path, ignore_errors=True)
    os.makedirs(to_hiera_path)

    # Copy only the static yaml files. The other yaml files will be generated
    # when required.
    for f in ['secure_static.yaml', 'static.yaml']:
        shutil.copy(os.path.join(from_hiera_path, f), to_hiera_path)

    # Make any necessary updates to the static yaml files.
    # Update the static.yaml file
    static_file = os.path.join(constants.HIERADATA_PERMDIR, "static.yaml")
    with open(static_file, 'r') as yaml_file:
        static_config = yaml.load(yaml_file)
    static_config.update({
        'platform::params::software_version': SW_VERSION,
        'platform::client::credentials::params::keyring_directory':
            KEYRING_PATH,
        'platform::client::credentials::params::keyring_file':
            os.path.join(KEYRING_PATH, '.CREDENTIAL'),
    })
    # Add dcmanager and sysinv user id as well as service project id to
    # the static.yaml on subclouds
    if (to_release == SW_VERSION_20_06 and
            role == sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SUBCLOUD):
        dm_user_id = utils.get_keystone_user_id('dcmanager')
        sysinv_user_id = utils.get_keystone_user_id('sysinv')
        service_project_id = utils.get_keystone_project_id('services')
        if dm_user_id:
            static_config.update({
                'platform::dcmanager::bootstrap::dc_dcmanager_user_id':
                    dm_user_id
            })
        if sysinv_user_id:
            static_config.update({
                'platform::sysinv::bootstrap::dc_sysinv_user_id':
                    sysinv_user_id
            })
        if service_project_id:
            static_config.update({
                'openstack::keystone::bootstrap::dc_services_project_id':
                    service_project_id
            })
    # Just for upgrade from STX4.0 to STX5.0
    if (from_release == SW_VERSION_20_06 and etcd_security_config):
        static_config.update(etcd_security_config)

    if from_release == SW_VERSION_20_06:
        # The helm db is new in the release stx5.0 and requires
        # a password to be generated and a new user to access the DB.
        # This is required for all types of system upgrade. Should
        # removed in the release that follows stx5.0
        static_config.update({
            'platform::helm::v2::db::postgresql::user': '******'
        })

        helmv2_db_pw = utils.get_password_from_keyring('helmv2', 'database')
        if not helmv2_db_pw:
            helmv2_db_pw = utils.set_password_in_keyring('helmv2', 'database')

        secure_static_file = os.path.join(
            constants.HIERADATA_PERMDIR, "secure_static.yaml")
        with open(secure_static_file, 'r') as yaml_file:
            secure_static_config = yaml.load(yaml_file)
        secure_static_config.update({
            'platform::helm::v2::db::postgresql::password': helmv2_db_pw
        })
        with open(secure_static_file, 'w') as yaml_file:
            yaml.dump(secure_static_config, yaml_file,
                      default_flow_style=False)

    with open(static_file, 'w') as yaml_file:
        yaml.dump(static_config, yaml_file, default_flow_style=False)