From 81847f1c17947a29f934ea681ec101419d318547 Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukalov Date: Mon, 13 Oct 2014 18:42:34 +0400 Subject: [PATCH] Some fixes in cloud-init templates in fuel-agent Added some new fields in config drive scheme. Change-Id: I76f36e555572a874f8f7b14951692927a7f00ddc Implements: blueprint image-based-provisioning --- cloud-init-templates/boothook_centos.jinja2 | 6 ++- .../cloud_config_centos.jinja2 | 54 +++++++++++-------- .../cloud_config_ubuntu.jinja2 | 40 ++++++++++---- fuel_agent/drivers/nailgun.py | 21 +++++--- fuel_agent/manager.py | 2 +- fuel_agent/objects/configdrive.py | 13 +++-- fuel_agent/objects/image.py | 4 +- fuel_agent/tests/test_configdrive.py | 8 +-- fuel_agent/tests/test_manager.py | 2 +- fuel_agent/tests/test_nailgun.py | 13 +++-- 10 files changed, 107 insertions(+), 56 deletions(-) diff --git a/cloud-init-templates/boothook_centos.jinja2 b/cloud-init-templates/boothook_centos.jinja2 index ef74424..2acd78c 100644 --- a/cloud-init-templates/boothook_centos.jinja2 +++ b/cloud-init-templates/boothook_centos.jinja2 @@ -94,7 +94,11 @@ cloud-init-per instance nailgun_agent echo 'flock -w 0 -o /var/lock/agent.lock - # Copying default bash settings to the root directory cloud-init-per instance skel_bash cp -f /etc/skel/.bash* /root/ +cloud-init-per instance clean_repos find /etc/yum.repos.d/. -name '*.repo' -delete + +# Puppet config cloud-init-per instance hiera_puppet mkdir -p /etc/puppet /var/lib/hiera cloud-init-per instance touch_puppet touch /var/lib/hiera/common.yaml /etc/puppet/hiera.yaml -cloud-init-per instance clean_repos find /etc/yum.repos.d/. -name '*.repo' -delete +# Mcollective enable +cloud-init-per instance mcollective_enable sed -i /etc/rc.d/init.d/mcollective -e 's/\(# chkconfig:\s\+[-0-6]\+\) [0-9]\+ \([0-9]\+\)/\1 81 \2/' diff --git a/cloud-init-templates/cloud_config_centos.jinja2 b/cloud-init-templates/cloud_config_centos.jinja2 index 2f4d6b3..22ad2e7 100644 --- a/cloud-init-templates/cloud_config_centos.jinja2 +++ b/cloud-init-templates/cloud_config_centos.jinja2 @@ -2,8 +2,14 @@ disable_ec2_metadata: true disable_root: false +# password: RANDOM +# chpasswd: { expire: True } + +ssh_pwauth: True ssh_authorized_keys: - - {{ common.ssh_auth_key }} +{% for key in common.ssh_auth_keys %} + - {{ key }} +{% endfor %} # set the locale to a given locale # default: en_US.UTF-8 @@ -24,7 +30,6 @@ resolv_conf: # rotate: true # timeout: 1 - # add entries to rsyslog configuration rsyslog: - filename: 10-log2master.conf @@ -32,15 +37,17 @@ rsyslog: $template LogToMaster, "<%%PRI%>1 %$NOW%T%TIMESTAMP:8:$%Z %HOSTNAME% %APP-NAME% %PROCID% %MSGID% -%msg%\n" *.* @{{ common.master_ip }};LogToMaster - -#TODO(agordeev): -#mounts: fill /etc/fstab - - runcmd: - - sed -i /etc/rc.d/init.d/mcollective -e 's/\(# chkconfig:\s\+[-0-6]\+\) [0-9]\+ \([0-9]\+\)/\1 81 \2/' - - /sbin/chkconfig mcollective on - +{% if puppet.enable != 1 %} + - service puppet stop + - chkconfig puppet off +{% endif %} +{% if mcollective.enable != 1 %} + - service mcollective stop + - chkconfig mcollective off +{% endif %} + - iptables -t filter -F INPUT + - iptables -t filter -F FORWARD # that module's missing in 0.6.3, but existent for >= 0.7.3 write_files: @@ -53,28 +60,34 @@ write_files: yum_repos: - {% for repo in common.ks_repos %} - {{ repo.name }}: - baseurl: {{ repo.url }} - enabled: true - gpgcheck: false - {% endfor %} +{% for reponame, repourl in common.ks_repos.items() %} + {{ reponame }}: + baseurl: {{ repourl }} + enabled: true + gpgcheck: false +{% endfor %} mcollective: conf: main_collective: mcollective collectives: mcollective - libdir: /usr/share/mcollective/plugins + libdir: /usr/libexec/mcollective logfile: /var/log/mcollective.log loglevel: debug daemonize: 1 - #NOTE: direct_addressing is 1 for ubuntu direct_addressing: 1 ttl: 4294957 securityprovider: psk plugin.psk: {{ mcollective.pskey }} - connector: {{ mcollective.connector }} +{% if mcollective.connector == 'stomp' %} + connector = stomp + plugin.stomp.host: {{ mcollective.host }} + plugin.stomp.port: {{ mcollective.port|default(61613) }} + plugin.stomp.user: {{ mcollective.user }} + plugin.stomp.password: {{ mcollective.password }} +{% else %} + connector: rabbitmq plugin.rabbitmq.vhost: {{ mcollective.vhost }} plugin.rabbitmq.pool.size: 1 plugin.rabbitmq.pool.1.host: {{ mcollective.host }} @@ -82,10 +95,10 @@ mcollective: plugin.rabbitmq.pool.1.user: {{ mcollective.user }} plugin.rabbitmq.pool.1.password: {{ mcollective.password }} plugin.rabbitmq.heartbeat_interval: 30 +{% endif %} factsource: yaml plugin.yaml: /etc/mcollective/facts.yaml - puppet: conf: main: @@ -102,4 +115,3 @@ puppet: final_message: "YAY! The system is finally up, after $UPTIME seconds" - diff --git a/cloud-init-templates/cloud_config_ubuntu.jinja2 b/cloud-init-templates/cloud_config_ubuntu.jinja2 index 5799e0b..34bddde 100644 --- a/cloud-init-templates/cloud_config_ubuntu.jinja2 +++ b/cloud-init-templates/cloud_config_ubuntu.jinja2 @@ -2,8 +2,11 @@ disable_ec2_metadata: true disable_root: false +ssh_pwauth: True ssh_authorized_keys: - - {{ common.ssh_auth_key }} +{% for key in common.ssh_auth_keys %} + - {{ key }} +{% endfor %} # set the locale to a given locale # default: en_US.UTF-8 @@ -33,9 +36,6 @@ rsyslog: *.* @{{ common.master_ip }};LogToMaster -#TODO(agordeev): -#mounts: fill /etc/fstab - # that module's missing in 0.6.3, but existent for >= 0.7.3 write_files: - content: | @@ -47,10 +47,10 @@ write_files: - content: APT::Get::AllowUnauthenticated 1; path: /etc/apt/apt.conf.d/02mirantis-allow-unsigned - apt_sources: - - source: deb http://{{ common.master_ip }}:8080/ubuntu/x86_64 precise main - +{% for reponame, repourl in common.ks_repos.items() %} + - source: deb {{ repourl }} +{% endfor %} mcollective: conf: @@ -59,12 +59,19 @@ mcollective: libdir: /usr/share/mcollective/plugins logfile: /var/log/mcollective.log loglevel: debug - daemonize: 1 - direct_addressing: 0 + daemonize: 0 + direct_addressing: 1 ttl: 4294957 securityprovider: psk plugin.psk: {{ mcollective.pskey }} - connector: {{ mcollective.connector }} +{% if mcollective.connector == 'stomp' %} + connector = stomp + plugin.stomp.host: {{ mcollective.host }} + plugin.stomp.port: {{ mcollective.port|default(61613) }} + plugin.stomp.user: {{ mcollective.user }} + plugin.stomp.password: {{ mcollective.password }} +{% else %} + connector: rabbitmq plugin.rabbitmq.vhost: {{ mcollective.vhost }} plugin.rabbitmq.pool.size: 1 plugin.rabbitmq.pool.1.host: {{ mcollective.host }} @@ -72,10 +79,10 @@ mcollective: plugin.rabbitmq.pool.1.user: {{ mcollective.user }} plugin.rabbitmq.pool.1.password: {{ mcollective.password }} plugin.rabbitmq.heartbeat_interval: 30 +{% endif %} factsource: yaml plugin.yaml: /etc/mcollective/facts.yaml - puppet: conf: main: @@ -90,5 +97,16 @@ puppet: report: false configtimeout: 600 +runcmd: +{% if puppet.enable != 1 %} + - /usr/sbin/invoke-rc.d puppet stop + - /usr/sbin/update-rc.d -f puppet remove +{% endif %} +{% if mcollective.enable != 1 %} + - /usr/sbin/invoke-rc.d mcollective stop + - /usr/sbin/update-rc.d -f mcollective remove +{% endif %} + - iptables -t filter -F INPUT + - iptables -t filter -F FORWARD final_message: "YAY! The system is finally up, after $UPTIME seconds" diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py index e66e4d7..b2c6489 100644 --- a/fuel_agent/drivers/nailgun.py +++ b/fuel_agent/drivers/nailgun.py @@ -226,8 +226,13 @@ class Nailgun(object): data['kernel_options']['netcfg/choose_interface']), [dict(name=name, **spec) for name, spec in data['interfaces'].iteritems()])[0] + + ssh_auth_keys = data['ks_meta']['authorized_keys'] + if data['ks_meta']['auth_key']: + ssh_auth_keys.append(data['ks_meta']['auth_key']) + configdrive_scheme.set_common( - ssh_auth_key=data['ks_meta']['auth_key'], + ssh_auth_keys=ssh_auth_keys, hostname=data['hostname'], fqdn=data['hostname'], name_servers=data['name_servers'], @@ -239,11 +244,14 @@ class Nailgun(object): admin_ip=admin_interface['ip_address'], admin_mask=admin_interface['netmask'], admin_iface_name=admin_interface['name'], - timezone=data['ks_meta']['timezone'], + timezone=data['ks_meta'].get('timezone', 'America/Los_Angeles'), + ks_repos=dict(item.split('=') for item in + data['ks_meta']['repo_metadata'].split(',')) ) configdrive_scheme.set_puppet( - master=data['ks_meta']['puppet_master'] + master=data['ks_meta']['puppet_master'], + enable=data['ks_meta']['puppet_enable'] ) configdrive_scheme.set_mcollective( @@ -252,7 +260,8 @@ class Nailgun(object): host=data['ks_meta']['mco_host'], user=data['ks_meta']['mco_user'], password=data['ks_meta']['mco_password'], - connector=data['ks_meta']['mco_connector'] + connector=data['ks_meta']['mco_connector'], + enable=data['ks_meta']['mco_enable'] ) configdrive_scheme.set_profile(profile=data['profile']) @@ -273,9 +282,9 @@ class Nailgun(object): image_scheme.add_image( uri=image_data['uri'], target_device=fs.device, - # In the future we will get image_format and container format + # In the future we will get format and container # from provision.json, but currently it is hard coded. - image_format=image_data['format'], + format=image_data['format'], container=image_data['container'], ) return image_scheme diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py index 694fc05..a44766d 100644 --- a/fuel_agent/manager.py +++ b/fuel_agent/manager.py @@ -134,7 +134,7 @@ class Manager(object): self.image_scheme.add_image( uri='file://%s' % CONF.config_drive_path, target_device=configdrive_device, - image_format='iso9660', + format='iso9660', container='raw' ) diff --git a/fuel_agent/objects/configdrive.py b/fuel_agent/objects/configdrive.py index 54e4f2d..c0aa9ef 100644 --- a/fuel_agent/objects/configdrive.py +++ b/fuel_agent/objects/configdrive.py @@ -16,10 +16,10 @@ from fuel_agent import errors class ConfigDriveCommon(object): - def __init__(self, ssh_auth_key, hostname, fqdn, name_servers, + def __init__(self, ssh_auth_keys, hostname, fqdn, name_servers, search_domain, master_ip, master_url, udevrules, admin_mac, - admin_ip, admin_mask, admin_iface_name, timezone): - self.ssh_auth_key = ssh_auth_key + admin_ip, admin_mask, admin_iface_name, timezone, ks_repos): + self.ssh_auth_keys = ssh_auth_keys self.hostname = hostname self.fqdn = fqdn self.name_servers = name_servers @@ -32,21 +32,24 @@ class ConfigDriveCommon(object): self.admin_mask = admin_mask self.admin_iface_name = admin_iface_name self.timezone = timezone + self.ks_repos = ks_repos class ConfigDrivePuppet(object): - def __init__(self, master): + def __init__(self, master, enable): self.master = master + self.enable = enable class ConfigDriveMcollective(object): - def __init__(self, pskey, vhost, host, user, password, connector): + def __init__(self, pskey, vhost, host, user, password, connector, enable): self.pskey = pskey self.vhost = vhost self.host = host self.user = user self.password = password self.connector = connector + self.enable = enable class ConfigDriveScheme(object): diff --git a/fuel_agent/objects/image.py b/fuel_agent/objects/image.py index 6c2ef2e..581dc9e 100644 --- a/fuel_agent/objects/image.py +++ b/fuel_agent/objects/image.py @@ -19,14 +19,14 @@ class Image(object): SUPPORTED_CONTAINERS = ['raw', 'gzip'] def __init__(self, uri, target_device, - image_format, container, size=None): + format, container, size=None): # uri is something like # http://host:port/path/to/image.img or # file:///tmp/image.img self.uri = uri self.target_device = target_device # this must be one of 'iso9660', 'ext[234]', 'xfs' - self.image_format = image_format + self.format = format if container not in self.SUPPORTED_CONTAINERS: raise errors.WrongImageDataError( 'Error while image initialization: ' diff --git a/fuel_agent/tests/test_configdrive.py b/fuel_agent/tests/test_configdrive.py index 5b6a209..4360d2b 100644 --- a/fuel_agent/tests/test_configdrive.py +++ b/fuel_agent/tests/test_configdrive.py @@ -40,13 +40,13 @@ class TestConfigDriveScheme(test_base.BaseTestCase): def test_template_data_ok(self): cd_common = configdrive.ConfigDriveCommon( - 'ssh_auth_key', 'hostname', 'fqdn', 'name_servers', + ['auth_key1', 'auth_key2'], 'hostname', 'fqdn', 'name_servers', 'search_domain', 'master_ip', 'master_url', 'udevrules', 'admin_mac', 'admin_ip', 'admin_mask', 'admin_iface_name', - 'timezone') - cd_puppet = configdrive.ConfigDrivePuppet('master') + 'timezone', {'repo1': 'repo1_url', 'repo2': 'repo2_url'}) + cd_puppet = configdrive.ConfigDrivePuppet('master', 0) cd_mcollective = configdrive.ConfigDriveMcollective( - 'pskey', 'vhost', 'host', 'user', 'password', 'connector') + 'pskey', 'vhost', 'host', 'user', 'password', 'connector', 1) self.cd_scheme.common = cd_common self.cd_scheme.puppet = cd_puppet self.cd_scheme.mcollective = cd_mcollective diff --git a/fuel_agent/tests/test_manager.py b/fuel_agent/tests/test_manager.py index 9ade4b7..a7e52ad 100644 --- a/fuel_agent/tests/test_manager.py +++ b/fuel_agent/tests/test_manager.py @@ -169,7 +169,7 @@ class TestManager(test_base.BaseTestCase): self.assertEqual('file://%s' % CONF.config_drive_path, cf_drv_img.uri) self.assertEqual('/dev/sda7', self.mgr.partition_scheme.configdrive_device()) - self.assertEqual('iso9660', cf_drv_img.image_format) + self.assertEqual('iso9660', cf_drv_img.format) self.assertEqual('raw', cf_drv_img.container) @mock.patch.object(partition.PartitionScheme, 'configdrive_device') diff --git a/fuel_agent/tests/test_nailgun.py b/fuel_agent/tests/test_nailgun.py index 8651298..3b17b5f 100644 --- a/fuel_agent/tests/test_nailgun.py +++ b/fuel_agent/tests/test_nailgun.py @@ -105,6 +105,8 @@ PROVISION_SAMPLE_DATA = { "puppet_master": "fuel.domain.tld", "mco_auto_setup": 1, "auth_key": "fake_auth_key", + "authorized_keys": ["fake_authorized_key1", "fake_authorized_key2"], + "repo_metadata": "repo1=repo1_url,repo2=repo2_url", "pm_data": { "kernel_params": "console=ttyS0,9600 console=tty0 rootdelay=90 " "nomodeset", @@ -441,7 +443,8 @@ class TestNailgun(test_base.BaseTestCase): def test_configdrive_scheme(self): cd_scheme = self.drv.configdrive_scheme() - self.assertEqual('fake_auth_key', cd_scheme.common.ssh_auth_key) + self.assertEqual(['fake_authorized_key1', 'fake_authorized_key2', + 'fake_auth_key'], cd_scheme.common.ssh_auth_keys) self.assertEqual('node-1.domain.tld', cd_scheme.common.hostname) self.assertEqual('node-1.domain.tld', cd_scheme.common.fqdn) self.assertEqual('node-1.domain.tld', cd_scheme.common.fqdn) @@ -465,6 +468,8 @@ class TestNailgun(test_base.BaseTestCase): self.assertEqual('marionette', cd_scheme.mcollective.password) self.assertEqual('rabbitmq', cd_scheme.mcollective.connector) self.assertEqual('ubuntu_1204_x86_64', cd_scheme.profile) + self.assertEqual({'repo1': 'repo1_url', 'repo2': 'repo2_url'}, + cd_scheme.common.ks_repos) @mock.patch.object(hu, 'list_block_devices') def test_partition_scheme(self, mock_lbd): @@ -490,7 +495,7 @@ class TestNailgun(test_base.BaseTestCase): expected_images.append(image.Image( uri=i_data['uri'], target_device=fs.device, - image_format=i_data['format'], + format=i_data['format'], container=i_data['container'], )) expected_images = sorted(expected_images, key=lambda x: x.uri) @@ -498,8 +503,8 @@ class TestNailgun(test_base.BaseTestCase): self.assertEqual(img.uri, expected_images[i].uri) self.assertEqual(img.target_device, expected_images[i].target_device) - self.assertEqual(img.image_format, - expected_images[i].image_format) + self.assertEqual(img.format, + expected_images[i].format) self.assertEqual(img.container, expected_images[i].container)