Skip to content

Commit

Permalink
Set interfaces by name if defined
Browse files Browse the repository at this point in the history
Change-Id: I8bcce63c2330247fbfbba0654f502b424385b8ef
  • Loading branch information
epcim committed May 30, 2018
1 parent 864a329 commit cf8d4c1
Show file tree
Hide file tree
Showing 14 changed files with 400 additions and 17 deletions.
86 changes: 86 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
driver:
name: docker
hostname: maas.ci.local
#socket: tcp://127.0.0.1:2376
use_sudo: false



provisioner:
name: salt_solo
salt_install: bootstrap
salt_bootstrap_url: https://bootstrap.saltstack.com
salt_version: latest
require_chef: false
formula: maas
log_level: info
state_top:
base:
"*":
- rsyslog
- postgresql
- maas
pillars:
top.sls:
base:
"*":
- rsyslog
- postgresql
- linux
- maas

pillars-from-files:
postgresql.sls: tests/pillar/postgresql.sls
rsyslog.sls: tests/pillar/rsyslog.sls
linux.sls: tests/pillar/linux.sls

grains:
noservices: False
kitchen-test: True

dependencies:
- name: postgresql
repo: git
source: https://github.com/salt-formulas/salt-formula-postgresql
- name: rsyslog
repo: git
source: https://github.com/salt-formulas/salt-formula-rsyslog


platforms:
- name: <%=ENV['PLATFORM'] || 'saltstack-ubuntu-xenial-salt-stable' %>
driver_config:
image: <%=ENV['PLATFORM'] || 'epcim/salt-formulas:saltstack-ubuntu-xenial-salt-stable'%>
platform: ubuntu


verifier:
name: inspec
sudo: true


suites:


- name: maas_cluster
provisioner:
pillars-from-files:
maas.sls: tests/pillar/maas_cluster.sls

#- name: disk_layout
#provisioner:
#pillars-from-files:
#maas.sls: tests/pillar/disk_layout.sls

#- name: maas_mirror
#provisioner:
#pillars-from-files:
#maas.sls: tests/pillar/maas_mirror.sls

#- name: maas_region
#provisioner:
#pillars-from-files:
#maas.sls: tests/pillar/maas_region.sls

# vim: ft=yaml sw=2 ts=2 sts=2 tw=125
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
sudo: required
services:
- docker

addons:
apt:
packages:
- apt-transport-https

install:
- pip install PyYAML
- pip install virtualenv
- |
test -e Gemfile || cat <<EOF > Gemfile
source 'https://rubygems.org'
gem 'rake'
gem 'test-kitchen'
gem 'kitchen-docker'
gem 'kitchen-inspec'
gem 'inspec'
gem 'kitchen-salt' #, :git => 'https://github.com/salt-formulas/kitchen-salt.git'
- bundle install

env:
- PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7
- PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3
# - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7

before_script:
- set -o pipefail
- make test | tail

script:
- test ! -e .kitchen.yml || bundle exec kitchen converge ${SUITE} || true
- test ! -e .kitchen.yml || bundle exec kitchen verify ${SUITE} -t tests/integration

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/6123573504759330786b
on_success: change # options: [always|never|change] default: always
on_failure: never # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
on_cancel: never # options: [always|never|change] default: always
on_error: never # options: [always|never|change] default: always
email: false
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ all:
@echo "make release-major - Generate new major release"
@echo "make release-minor - Generate new minor release"
@echo "make changelog - Show changes since last release"
@echo "make test-model-validate - Run salt jsonschema validation"

install:
# Formula
[ -d $(DESTDIR)/$(SALTENVDIR) ] || mkdir -p $(DESTDIR)/$(SALTENVDIR)
cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
[ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
[ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
[ ! -d _engines ] || cp -a _engines $(DESTDIR)/$(SALTENVDIR)/ || true
[ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true
# Metadata
[ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
Expand All @@ -52,6 +54,10 @@ lint:
test:
[ ! -d tests ] || (cd tests; ./run_tests.sh)

test-model-validate:
# TODO make it actually fail
[ ! -d $(FORMULANAME)/schemas/ ] || (cd tests; ./run_tests.sh model-validate)

release-major: check-changes
@echo "Current version is $(VERSION), new version is $(NEW_MAJOR_VERSION)"
@[ $(VERSION_MAJOR) != $(NEW_MAJOR_VERSION) ] || (echo "Major version $(NEW_MAJOR_VERSION) already released, nothing to do. Do you want release-minor?" && exit 1)
Expand Down
29 changes: 29 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ Single maas service
server:
enabled: true
Configure node interfaces.

Interfaces are identified by provided `name` or by `mac` if `name` is not provided or not found.
When configured name is not found interface name will be renamed.

.. code-block:: yaml
maas:
region:
machines:
machine1:
pxe_interface_mac: "11:22:33:44:55:66"
interfaces:
nic01:
name: eth0
mac: "11:22:33:44:55:66"
mode: "static"
ip: "2.2.3.19"
subnet: "subnet1"
gateway: "2.2.3.2"
Single MAAS region service [single UI/API]

.. code-block:: yaml
Expand Down Expand Up @@ -471,6 +492,14 @@ MAAS region service with backup data
source: cfg01.local
host: 192.168.0.11
Test pillars
==============

Mind the postgresql and rsyslog `.sls`. Database and syslog service are required for MAAS to properly install and work.

* https://github.com/salt-formulas/salt-formula-rsyslog/tree/master/tests/pillar


Module function's example:
==========================

Expand Down
25 changes: 24 additions & 1 deletion _modules/maas.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,18 @@ def _get_nic_id_by_mac(self, machine, req_mac=None):
'node:{}'.format(req_mac, machine['fqdn']))
return data

def _get_nic_id_by_name(self, machine, req_name=None):
data = {}
for nic in machine['interface_set']:
data[nic['name']] = nic['id']
if req_name:
if req_name in data.keys():
return data[req_name]
else:
raise Exception('NIC with name:{} not found at '
'node:{}'.format(req_name, machine['fqdn']))
return data

def _disconnect_all_nic(self, machine):
"""
Maas will fail, in case same config's will be to apply
Expand Down Expand Up @@ -538,7 +550,18 @@ def _process_interface(self, nic_data, machine):
external "process" method. Those broke old-MaasObject logic,
though make functions more simple in case iterable tasks.
"""
nic_id = self._get_nic_id_by_mac(machine, nic_data['mac'])

if nic_data.has_key('name'):
try:
nic_id = self._get_nic_id_by_mac(machine, nic_data['name'])
except Exception as e:
LOG.warn("Failed to find interface: {} on node: {}. Will try now by its MAC: {}".format(
nic_data['name'], machine['fqdn'], nic_data['mac_address']))
nic_id = False

if not nic_id:
# assume MAC is always provided
nic_id = self._get_nic_id_by_mac(machine, nic_data['mac'])

# Process op=link_subnet
link_data = {}
Expand Down
3 changes: 3 additions & 0 deletions maas/cluster.sls
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,8 @@ maas_cluster_services:
- file: /etc/maas/rackd.conf
- watch:
- file: /etc/maas/rackd.conf
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
{%- endif %}
8 changes: 8 additions & 0 deletions maas/files/regiond.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{%- from "maas/map.jinja" import region with context %}

{%- if region.database.host is defined %}
database_host: {{ region.database.host }}
{%- endif %}
{%- if region.database.name is defined %}
database_name: {{ region.database.name }}
{%- endif %}
{%- if region.database.password is defined %}
database_pass: {{ region.database.password }}
{%- endif %}
{%- if region.database.username is defined %}
database_user: {{ region.database.username }}
{%- endif %}
maas_url: http://{{ region.bind.host }}/MAAS
22 changes: 20 additions & 2 deletions maas/region.sls
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ maas_apache_headers:
- require:
- pkg: maas_region_packages
/root/.pgpass:
Configure /root/.pgpass for MAAS:
file.managed:
- name: /root/.pgpass
- source: salt://maas/files/pgpass
- template: jinja
- user: root
Expand All @@ -125,11 +126,14 @@ maas_region_services:
- cmd: maas_region_syncdb
- watch:
- file: /etc/maas/regiond.conf
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
maas_region_syncdb:
cmd.run:
- names:
- maas-region syncdb
- maas-region syncdb --noinput
- require:
- file: /etc/maas/regiond.conf
Expand All @@ -139,16 +143,27 @@ maas_set_admin_password:
- creates: /var/lib/maas/.setup_admin
- require:
- service: maas_region_services
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
maas_login_admin:
cmd.run:
- name: "maas-region apikey --username {{ region.admin.username }} > /var/lib/maas/.maas_credentials"
- require:
- cmd: maas_set_admin_password
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
maas_config:
module.run:
- name: maas.process_maas_config
- require:
- cmd: maas_login_admin
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
{%- if region.get('boot_sources', False) %}
maas_boot_sources:
Expand Down Expand Up @@ -243,6 +258,9 @@ maas_domain:
- name: maas.process_domain
- require:
- module: maas_config
{%- if grains.get('kitchen-test') %}
- onlyif: /bin/false
{%- endif %}
{%- if region.fabrics is defined %}
{%- for fabric_name, fabric in region.fabrics.iteritems() %}
Expand Down
5 changes: 5 additions & 0 deletions metadata.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
name: "maas"
version: "0.1"
source: "https://github.com/salt-formulas/salt-formula-maas"
dependencies:
- name: postgresql
source: "https://github.com/salt-formulas/salt-formula-postgresql"
- name: rsyslog
source: "https://github.com/salt-formulas/salt-formula-rsyslog"
3 changes: 3 additions & 0 deletions tests/pillar/linux.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linux:
system:
domain: ci.local
Loading

0 comments on commit cf8d4c1

Please sign in to comment.