Merge pull request #31 from alexandruavadanii/curtin-arm64-typo

curtin: arm64: Fix missing newline after j2 parse
diff --git a/.kitchen.yml b/.kitchen.yml
new file mode 100644
index 0000000..ca02fdf
--- /dev/null
+++ b/.kitchen.yml
@@ -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
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cb33408
--- /dev/null
+++ b/.travis.yml
@@ -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:saltstack-ubuntu-xenial-salt-2016.3
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7
+    - PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-stable
+
+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
diff --git a/Makefile b/Makefile
index d166862..f9b4f47 100644
--- a/Makefile
+++ b/Makefile
@@ -34,6 +34,7 @@
 	@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
@@ -41,6 +42,7 @@
 	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)
@@ -52,6 +54,10 @@
 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)
diff --git a/README.rst b/README.rst
index e466959..d08ec42 100644
--- a/README.rst
+++ b/README.rst
@@ -250,7 +250,7 @@
       machines:
         server3:
           disk_layout:
-            type: flat #This is simplies setup
+            type: custom
             bootable_device: vda
             disk:
               vda:
@@ -316,8 +316,8 @@
       machines:
         serverWithRaidExample:
           disk_layout:
-            #type: flat
-            #bootable_device: sda
+            type: custom
+            bootable_device: sda
             disk:
               md0:
                 type: raid
@@ -356,7 +356,7 @@
       machines:
         serverWithRaidExample2:
           disk_layout:
-            #type: flat
+            type: custom
             #bootable_device: vgssd-root
             disk:
               sda: &maas_disk_physical_ssd
@@ -471,6 +471,14 @@
             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:
 ==========================
 
diff --git a/_modules/maasng.py b/_modules/maasng.py
index 1939b80..8e4d1f2 100644
--- a/_modules/maasng.py
+++ b/_modules/maasng.py
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-'''
+"""
 Module for handling maas calls.
 
 :optdepends:    pyapi-maas Python adapter
@@ -9,7 +9,7 @@
         maas.url: 'https://maas.domain.com/'
         maas.token: fdsfdsdsdsfa:fsdfae3fassd:fdsfdsfsafasdfsa
 
-'''
+"""
 
 from __future__ import absolute_import
 
@@ -50,10 +50,10 @@
 
 
 def __virtual__():
-    '''
+    """
     Only load this module if maas-client
     is installed on this minion.
-    '''
+    """
     if HAS_MASS:
         return 'maasng'
     return False
@@ -95,6 +95,15 @@
     return list_volume_groups(hostname)[device]["id"]
 
 
+def _get_volume_id_by_name(hostname, volume_name, volume_group, maas_volname=True):
+
+    if not maas_volname:
+        # MAAS-like name
+        volume_name = str("%s-%s" % (volume_group,volume_name))
+    ##TODO validation
+    return get_volumes(hostname, volume_group)[volume_name]["id"]
+
+
 def _get_partition_id_by_name(hostname, device, partition):
 
     # TODO validation
@@ -104,7 +113,7 @@
 
 
 def get_machine(hostname):
-    '''
+    """
     Get information aboout specified machine
 
     CLI Example:
@@ -112,7 +121,7 @@
     .. code-block:: bash
 
         salt-call maasng.get_machine server_hostname
-    '''
+    """
     try:
         return list_machines()[hostname]
     except KeyError:
@@ -120,7 +129,7 @@
 
 
 def list_machines():
-    '''
+    """
     Get list of all machines from maas server
 
     CLI Example:
@@ -128,7 +137,7 @@
     .. code-block:: bash
 
         salt 'maas-node' maasng.list_machines
-    '''
+    """
     machines = {}
     maas = _create_maas_client()
     json_res = json.loads(maas.get(u'api/2.0/machines/').read())
@@ -148,14 +157,12 @@
 
     return False
 
-# MACHINE OPERATIONS
-# TODO
-
+# END MACHINE SECTION
 # RAID SECTION
 
 
 def create_raid(hostname, name, level, disks=[], partitions=[], **kwargs):
-    '''
+    """
     Create new raid on machine.
 
     CLI Example:
@@ -163,7 +170,7 @@
     .. code-block:: bash
 
         salt-call maasng.create_raid hostname=kvm03 name=md0 level=1 disks=[vdb,vdc] partitions=[vdd-part1,vde-part1]
-    '''
+    """
 
     result = {}
 
@@ -213,7 +220,7 @@
 
 
 def list_raids(hostname):
-    '''
+    """
     Get list all raids on machine
 
     CLI Example:
@@ -221,22 +228,21 @@
     .. code-block:: bash
 
         salt-call maasng.list_raids server_hostname
-    '''
+    """
 
+    raids = {}
     maas = _create_maas_client()
     system_id = get_machine(hostname)["system_id"]
-    LOG.info(system_id)
-    # TODO validation
-    json_res = json.loads(
-        maas.get(u"api/2.0/nodes/{0}/raids/".format(system_id)).read())
-    LOG.info(json_res)
-
-    # TODO return list of raid devices
-    return True
+    #TODO validation
+    json_res = json.loads(maas.get(u"api/2.0/nodes/{0}/raids/".format(system_id)).read())
+    LOG.debug('list_raids:{} {}'.format(system_id, json_res))
+    for item in json_res:
+        raids[item["name"]] = item
+    return raids
 
 
 def get_raid(hostname, name):
-    '''
+    """
     Get information about specific raid on machine
 
     CLI Example:
@@ -244,15 +250,42 @@
     .. code-block:: bash
 
         salt-call maasng.get_raids server_hostname md0
-    '''
+    """
 
     return list_raids(hostname)[name]
 
 
+def _get_raid_id_by_name(hostname, raid_name):
+    return get_raid(hostname, raid_name)['id']
+
+
+def delete_raid(hostname, raid_name):
+    """
+    Delete RAID on a machine.
+
+    CLI Example:
+
+    .. code-block:: bash
+
+        salt 'maas-node' maasng.delete_raid server_hostname raid_name
+        salt-call maasng.delete_raid server_hostname raid_name
+    """
+    result = {}
+    maas=_create_maas_client()
+    system_id = get_machine(hostname)["system_id"]
+    raid_id = _get_raid_id_by_name(hostname, raid_name)
+    LOG.debug('delete_raid: {} {}'.format(system_id,raid_id))
+    maas.delete(u"api/2.0/nodes/{0}/raid/{1}/".format(system_id, raid_id)).read()
+
+    result["new"] = "Raid {0} deleted".format(raid_name)
+    return result
+
+# END RAID SECTION
 # BLOCKDEVICES SECTION
 
+
 def list_blockdevices(hostname):
-    '''
+    """
     Get list of all blockdevices (disks) on machine
 
     CLI Example:
@@ -261,7 +294,7 @@
 
         salt 'maas-node' maasng.list_blockdevices server_hostname
         salt-call maasng.list_blockdevices server_hostname
-    '''
+    """
     ret = {}
 
     maas = _create_maas_client()
@@ -280,7 +313,7 @@
 
 
 def get_blockdevice(hostname, name):
-    '''
+    """
     Get information about blockdevice (disk) on machine
 
     CLI Example:
@@ -289,15 +322,16 @@
 
         salt 'maas-node' maasng.get_blockdevice server_hostname sda
         salt-call maasng.get_blockdevice server_hostname sda
-    '''
+    """
 
     return list_blockdevices(hostname)[name]
 
-
+# END BLOCKDEVICES SECTION
 # PARTITIONS
 
+
 def list_partitions(hostname, device):
-    '''
+    """
     Get list of all partitions on specific device located on specific machine
 
     CLI Example:
@@ -306,7 +340,7 @@
 
         salt 'maas-node' maasng.list_partitions server_hostname sda
         salt-call maasng.list_partitions server_hostname sda
-    '''
+    """
     ret = {}
     maas = _create_maas_client()
     system_id = get_machine(hostname)["system_id"]
@@ -327,7 +361,7 @@
 
 
 def get_partition(hostname, device, partition):
-    '''
+    """
     Get information about specific parition on device located on machine
 
     CLI Example:
@@ -338,13 +372,13 @@
         salt-call maasng.get_partition server_hostname disk_name partition
 
         root_size = size in GB
-    '''
+    """
 
     return list_partitions(partition)[name]
 
 
 def create_partition(hostname, disk, size, fs_type=None, mount=None):
-    '''
+    """
     Create new partition on device.
 
     CLI Example:
@@ -353,7 +387,7 @@
 
         salt 'maas-node' maasng.create_partition server_hostname disk_name 10 ext4 "/"
         salt-call maasng.create_partition server_hostname disk_name 10 ext4 "/"
-    '''
+    """
     # TODO validation
     result = {}
     maas = _create_maas_client()
@@ -404,7 +438,7 @@
 
 
 def delete_partition(hostname, disk, partition_name):
-    '''
+    """
     Delete partition on device.
 
     CLI Example:
@@ -415,7 +449,7 @@
         salt-call maasng.delete_partition server_hostname disk_name partition_name
 
         root_size = size in GB
-    '''
+    """
     result = {}
     data = {}
     maas = _create_maas_client()
@@ -434,7 +468,7 @@
 
 
 def delete_partition_by_id(hostname, disk, partition_id):
-    '''
+    """
     Delete partition on device. Partition spefified by id of parition
 
     CLI Example:
@@ -445,7 +479,7 @@
         salt-call maasng.delete_partition_by_id server_hostname disk_name partition_id
 
         root_size = size in GB
-    '''
+    """
     result = {}
     data = {}
     maas = _create_maas_client()
@@ -459,13 +493,41 @@
         system_id, device_id, partition_id)).read()
     result["new"] = "Partition {0} deleted".format(partition_id)
     return result
+# END PARTITIONS
+# DISK LAYOUT
 
-# CREATE DISK LAYOUT
-# TODO
+
+def drop_storage_schema(hostname,disk=None):
+    """
+    #1. Drop lv
+    #2. Drop vg
+    #3. Drop md # need to zero-block?
+    #3. Drop part
+    """
+
+    if __opts__['test']:
+        ret['result'] = None
+        ret['comment'] = 'Storage schema on {0} will be removed'.format(hostname)
+        return ret
+    #TODO validation if exists
+    vgs = list_volume_groups(hostname)
+    for vg in vgs:
+        delete_volume_group(hostname, vg)
+
+    raids = list_raids(hostname)
+    for raid in raids:
+        delete_raid(hostname, raid)
+
+    blocks = list_blockdevices(hostname)
+    for block_d in blocks:
+        partitions = __salt__['maasng.list_partitions'](hostname, block_d)
+        for partition_name, partition in partitions.iteritems():
+            LOG.info('delete partition:\n{}'.format(partition))
+            __salt__['maasng.delete_partition_by_id'](hostname, block_d, partition["id"])
 
 
 def update_disk_layout(hostname, layout, root_size=None, root_device=None, volume_group=None, volume_name=None, volume_size=None):
-    '''
+    """
     Update disk layout. Flat or LVM layout supported.
 
     CLI Example:
@@ -476,7 +538,7 @@
         salt-call maasng.update_disk_layout server_hostname lvm root_size=None, root_device=None, volume_group=None, volume_name=None, volume_size=None
 
         root_size = size in GB
-    '''
+    """
     result = {}
     data = {
         "storage_layout": layout,
@@ -486,6 +548,14 @@
     system_id = get_machine(hostname)["system_id"]
     LOG.info(system_id)
 
+    if layout == 'custom':
+        drop_storage_schema(hostname)
+        result["new"] = {
+            "storage_layout": layout,
+        }
+
+        return result
+
     if root_size != None:
         bit_size = str(root_size * 1073741824)
         LOG.info(bit_size)
@@ -518,12 +588,11 @@
 
     return result
 
-
+# END DISK LAYOUT
 # LVM
-# TODO
 
 def list_volume_groups(hostname):
-    '''
+    """
     Get list of all volume group on machine.
 
     CLI Example:
@@ -532,7 +601,7 @@
 
         salt 'maas-node' maasng.list_volume_groups server_hostname
         salt-call maasng.list_volume_groups server_hostname
-    '''
+    """
     volume_groups = {}
 
     maas = _create_maas_client()
@@ -551,7 +620,7 @@
 
 
 def get_volume_group(hostname, name):
-    '''
+    """
     Get information about specific volume group on machine.
 
     CLI Example:
@@ -560,13 +629,13 @@
 
         salt 'maas-node' maasng.list_blockdevices server_hostname
         salt-call maasng.list_blockdevices server_hostname
-    '''
+    """
     # TODO validation that exists
     return list_volume_groups(hostname)[name]
 
 
 def create_volume_group(hostname, volume_group_name, disks=[], partitions=[]):
-    '''
+    """
     Create new volume group on machine. Disks or partitions needs to be provided.
 
     CLI Example:
@@ -575,7 +644,7 @@
 
         salt 'maas-node' maasng.create_volume_group volume_group_name, disks=[sda,sdb], partitions=[]
         salt-call maasng.create_volume_group server_hostname
-    '''
+    """
     result = {}
 
     data = {
@@ -623,7 +692,7 @@
 
 
 def delete_volume_group(hostname, name):
-    '''
+    """
     Delete volume group on machine.
 
     CLI Example:
@@ -632,30 +701,25 @@
 
         salt 'maas-node' maasng.delete_volume_group server_hostname vg0
         salt-call maasng.delete_volume_group server_hostname vg0
-    '''
+    """
 
     maas = _create_maas_client()
     system_id = get_machine(hostname)["system_id"]
-    LOG.info(system_id)
+    LOG.debug('delete_volume_group:{}'.format(system_id))
 
-    # TODO partitions
-    # for partition in partitions:
-    #    temp = disk.split("-")
-    #    disk_ids.append(str(_get_blockdevice_id_by_name(hostname, temp[] partition)))
+    vg_id = str(_get_volume_group_id_by_name(hostname, name))
+    for vol in get_volumes(hostname, name):
+        delete_volume(hostname,vol,name)
 
-    # TODO partitions
-    vg_id = name
-
-    # TODO validation
-    json_res = json.loads(maas.delete(
-        u"api/2.0/nodes/{0}/volume-group/{1}/".format(system_id, vg_id)).read())
+    #TODO validation
+    json_res = json.loads(maas.delete(u"api/2.0/nodes/{0}/volume-group/{1}/".format(system_id, vg_id)).read() or 'null')
     LOG.info(json_res)
 
     return True
 
 
 def create_volume(hostname, volume_name, volume_group, size, fs_type=None, mount=None):
-    '''
+    """
     Create volume on volume group.
 
     CLI Example:
@@ -664,7 +728,7 @@
 
         salt 'maas-node' maasng.create_volume server_hostname volume_name, volume_group, size, fs_type=None, mount=None
         salt-call maasng.create_volume server_hostname volume_name, volume_group, size, fs_type=None, mount=None
-    '''
+    """
 
     data = {
         "name": volume_name,
@@ -690,12 +754,59 @@
     LOG.info(json_res)
 
     if fs_type != None or mount != None:
-        ret = create_volume_filesystem(
-            hostname, volume_group + "-" + volume_name, fs_type, mount)
+        ret = create_volume_filesystem(hostname, volume_group + "-" + volume_name, fs_type, mount)
 
     return True
 
 
+def delete_volume(hostname, volume_name, volume_group):
+    """
+    Delete volume from volume group.
+    Tips: maas always use 'volume_group-volume_name' name schema.Example: 'vg0-glusterfs'
+          This function expexts same format.
+
+    CLI Example:
+
+    .. code-block:: bash
+
+        salt 'maas-node' maasng.delete_volume server_hostname volume_name volume_group
+        salt 'maas-node' maasng.delete_volume server_hostname vg0-vol0 vg0
+        salt-call maasng.delete_volume server_hostname volume_name volume_group
+    """
+
+    maas=_create_maas_client()
+    system_id = get_machine(hostname)["system_id"]
+    LOG.debug('delete_volume:{}'.format(system_id))
+
+    volume_group_id = str(_get_volume_group_id_by_name(hostname, volume_group))
+    volume_id = str(_get_volume_id_by_name(hostname, volume_name, volume_group))
+
+    if None in [volume_group_id, volume_id]:
+        return False
+
+    data = {
+        "id": volume_id,
+    }
+
+    #TODO validation
+    json_res = json.loads(maas.post(u"api/2.0/nodes/{0}/volume-group/{1}/".format(system_id, volume_group_id), "delete_logical_volume", **data).read() or 'null')
+    return True
+
+
+def get_volumes(hostname, vg_name):
+    """
+    Get list of volumes in volume group.
+    """
+    volumes = {}
+    _volumes = list_volume_groups(hostname)[vg_name].get('logical_volumes', False)
+    if _volumes:
+        for item in _volumes:
+            volumes[item["name"]] = item
+    return volumes
+
+# END LVM
+
+
 def create_volume_filesystem(hostname, device, fs_type=None, mount=None):
 
     maas = _create_maas_client()
@@ -720,32 +831,8 @@
     return True
 
 
-def create_partition_filesystem(hostname, partition, fs_type=None, mount=None):
-
-    maas = _create_maas_client()
-    system_id = get_machine(hostname)["system_id"]
-
-    blockdevices_id = _get_blockdevice_id_by_name(hostname, device)
-    data = {}
-    if fs_type != None:
-        data["fstype"] = fs_type
-        # TODO validation
-        json_res = json.loads(maas.post(u"/api/2.0/nodes/{0}/blockdevices/{1}/".format(
-            system_id, blockdevices_id), "format", **data).read())
-        LOG.info(json_res)
-
-    if mount != None:
-        data["mount_point"] = mount
-        # TODO validation
-        json_res = json.loads(maas.post(u"/api/2.0/nodes/{0}/blockdevices/{1}/".format(
-            system_id, blockdevices_id), "mount", **data).read())
-        LOG.info(json_res)
-
-    return True
-
-
 def set_boot_disk(hostname, name):
-    '''
+    """
     Create volume on volume group.
 
     CLI Example:
@@ -754,7 +841,7 @@
 
         salt 'maas-node' maasng.set_boot_disk server_hostname disk_name
         salt-call maasng.set_boot_disk server_hostname disk_name
-    '''
+    """
     data = {}
     result = {}
     maas = _create_maas_client()
@@ -768,9 +855,11 @@
 
     return result
 
+# NETWORKING
+
 
 def list_fabric():
-    '''
+    """
     Get list of all fabric
 
     CLI Example:
@@ -778,7 +867,7 @@
     .. code-block:: bash
 
         salt 'maas-node' maasng.list_fabric
-    '''
+    """
     fabrics = {}
     maas = _create_maas_client()
     json_res = json.loads(maas.get(u'api/2.0/fabrics/').read())
@@ -789,7 +878,7 @@
 
 
 def create_fabric(name):
-    '''
+    """
     Create new fabric.
 
     CLI Example:
@@ -797,7 +886,7 @@
     .. code-block:: bash
 
         salt 'maas-node' maasng.create_fabric
-    '''
+    """
     result = {}
     data = {
         "name": name,
@@ -814,7 +903,7 @@
 
 
 def list_subnet():
-    '''
+    """
     Get list of all subnets
 
     CLI Example:
@@ -822,7 +911,7 @@
     .. code-block:: bash
 
         salt 'maas-node' maasng.list_subnet
-    '''
+    """
     subnets = {}
     maas = _create_maas_client()
     json_res = json.loads(maas.get(u'api/2.0/subnets/').read())
@@ -833,7 +922,7 @@
 
 
 def list_vlans(fabric):
-    '''
+    """
     Get list of all vlans for specific fabric
 
     CLI Example:
@@ -841,7 +930,7 @@
     .. code-block:: bash
 
         salt 'maas-node' maasng.list_vlans
-    '''
+    """
     vlans = {}
     maas = _create_maas_client()
     fabric_id = get_fabric(fabric)
@@ -855,7 +944,7 @@
 
 
 def get_fabric(fabric):
-    '''
+    """
     Get id for specific fabric
 
     CLI Example:
@@ -863,15 +952,15 @@
     .. code-block:: bash
 
         salt-call maasng.get_fabric fabric_name
-    '''
+    """
     try:
         return list_fabric()[fabric]['id']
     except KeyError:
         return {"error": "Frabic not found on MaaS server"}
 
 
-def update_vlan(name, fabric, vid, description, dhcp_on=False):
-    '''
+def update_vlan(name, fabric, vid, description, primary_rack, dhcp_on=False):
+    """
     Update vlan
 
     CLI Example:
@@ -879,13 +968,14 @@
     .. code-block:: bash
 
         salt 'maas-node' maasng.update_vlan name, fabric, vid, description, dhcp_on
-    '''
+    """
     result = {}
 
     data = {
         "name": name,
         "dhcp_on": str(dhcp_on),
         "description": description,
+        "primary_rack": primary_rack,
     }
     maas = _create_maas_client()
     fabric_id = get_fabric(fabric)
@@ -896,3 +986,5 @@
     result["new"] = "Vlan {0} was updated".format(json_res["name"])
 
     return result
+
+# END NETWORKING
diff --git a/_states/maasng.py b/_states/maasng.py
index ad30025..3d23311 100644
--- a/_states/maasng.py
+++ b/_states/maasng.py
@@ -64,6 +64,9 @@
         ret["changes"] = __salt__['maasng.update_disk_layout'](
             hostname, layout_type, root_size, root_device, volume_group, volume_name, volume_size)
 
+    elif layout_type == "custom":
+        ret["changes"] = __salt__['maasng.update_disk_layout'](hostname, layout_type)
+
     else:
         ret["comment"] = "Not supported layout provided. Choose flat or lvm"
         ret['result'] = False
@@ -325,7 +328,7 @@
     return ret
 
 
-def update_vlan(name, fabric, vid, description, dhcp_on=False):
+def update_vlan(name, fabric, vid, description, primary_rack, dhcp_on=False):
     '''
 
     :param name: Name of vlan
@@ -333,6 +336,7 @@
     :param vid: Vlan id
     :param description: Description of vlan
     :param dhcp_on: State of dhcp
+    :param primary_rack: primary_rack
 
     '''
 
@@ -342,7 +346,7 @@
            'comment': 'Module function maasng.update_vlan executed'}
 
     ret["changes"] = __salt__['maasng.update_vlan'](
-        name=name, fabric=fabric, vid=vid, description=description, dhcp_on=dhcp_on)
+        name=name, fabric=fabric, vid=vid, description=description, primary_rack=primary_rack, dhcp_on=dhcp_on)
 
     if "error" in fabric:
         ret['comment'] = "State execution failed for fabric {0}".format(fabric)
diff --git a/maas/cluster.sls b/maas/cluster.sls
index 9fe61bf..59284db 100644
--- a/maas/cluster.sls
+++ b/maas/cluster.sls
@@ -62,5 +62,8 @@
     - file: /etc/maas/rackd.conf
   - watch:
     - file: /etc/maas/rackd.conf
+  {%- if grains.get('kitchen-test') %}
+  - onlyif: /bin/false
+  {%- endif %}
 
 {%- endif %}
diff --git a/maas/files/restore.sh b/maas/files/restore.sh
index 121b1b4..b263a29 100644
--- a/maas/files/restore.sh
+++ b/maas/files/restore.sh
@@ -1,6 +1,7 @@
 {%- from "maas/map.jinja" import region with context %}
 
-{%- set database = region.get("database", {}) %}
+{%- set backup_dir = pillar.get('backupninja', {}).get('client', {}).get('target', {}).get("home_dir", "/srv/backupninja") -%}
+{%- set database = region.get("database", {}) -%}
 
 export PGHOST={{ database.get("host", "localhost") }}
 export PGUSER={{ database.get("username", "maas") }}
@@ -18,11 +19,11 @@
 
 mkdir -p {{ target }}
 
-scp backupninja@{{ backupninja_host }}:/srv/backupninja/{{ backupninja_source }}/var/backups/postgresql/postgresql.{{ age }}/{{ source_name }} {{ target }}{{ dest_name }} 
+scp backupninja@{{ backupninja_host }}:{{ backup_dir }}/{{ backupninja_source }}/var/backups/postgresql/postgresql.{{ age }}/{{ source_name }} {{ target }}{{ dest_name }} 
 gunzip -d -1 -f {{ target }}{{ dest_name }}
 
-scp -r backupninja@{{ backupninja_host }}:/srv/backupninja/{{ backupninja_source }}/etc/maas/maas.{{ age }} /etc/maas
-scp -r backupninja@{{ backupninja_host }}:/srv/backupninja/{{ backupninja_source }}/var/lib/maas/maas.{{ age }} /var/lib/maas
+scp -r backupninja@{{ backupninja_host }}:{{ backup_dir }}/{{ backupninja_source }}/etc/maas/maas.{{ age }} /etc/maas
+scp -r backupninja@{{ backupninja_host }}:{{ backup_dir }}/{{ backupninja_source }}/var/lib/maas/maas.{{ age }} /var/lib/maas
 
 sudo systemctl stop maas-dhcpd.service
 sudo systemctl stop maas-rackd.service
diff --git a/maas/map.jinja b/maas/map.jinja
index bcf8a48..6a0a201 100644
--- a/maas/map.jinja
+++ b/maas/map.jinja
@@ -29,6 +29,7 @@
 Debian:
   pkgs:
   - simplestreams
+  - ubuntu-cloudimage-keyring
 {%- endload %}
 
 {%- set mirror = salt['grains.filter_by'](mirror_defaults, merge=salt['pillar.get']('maas:mirror', {})) %}
diff --git a/maas/region.sls b/maas/region.sls
index e129457..2047307 100644
--- a/maas/region.sls
+++ b/maas/region.sls
@@ -109,8 +109,9 @@
   - 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
@@ -125,13 +126,22 @@
     - 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
+  {%- if grains['saltversioninfo'][0] >= 2017 and grains['saltversioninfo'][1] >= 7 %}
+  - retry:
+    attempts: 3
+    interval: 5
+    splay: 5
+  {%- endif %}
 
 maas_set_admin_password:
   cmd.run:
@@ -139,16 +149,27 @@
   - 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:
@@ -243,6 +264,9 @@
   - 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() %}
@@ -253,6 +277,7 @@
   - fabric: {{ fabric_name }}
   - name: {{ vlan.get('name','') }}
   - description: {{ vlan.description }}
+  - primary_rack: {{ region.maas_config.maas_name }}
   - dhcp_on: {{ vlan.get('dhcp','False') }}
 {%- endfor %}
 {%- endfor %}
diff --git a/metadata.yml b/metadata.yml
index dacbd6f..72d1aea 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -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"
diff --git a/tests/pillar/linux.sls b/tests/pillar/linux.sls
new file mode 100644
index 0000000..a150747
--- /dev/null
+++ b/tests/pillar/linux.sls
@@ -0,0 +1,3 @@
+linux:
+  system:
+    domain: ci.local
diff --git a/tests/pillar/maas_cluster.sls b/tests/pillar/maas_cluster.sls
index af63517..641cfb6 100644
--- a/tests/pillar/maas_cluster.sls
+++ b/tests/pillar/maas_cluster.sls
@@ -1,11 +1,46 @@
 maas:
   cluster:
     enabled: true
+    role: master
     region:
+      port: 80
       host: localhost
-    role: slave
+    saltstack_repo_key: |
+      -----BEGIN PGP PUBLIC KEY BLOCK-----
+      Version: GnuPG v2
+
+      mQENBFOpvpgBCADkP656H41i8fpplEEB8IeLhugyC2rTEwwSclb8tQNYtUiGdna9
+      m38kb0OS2DDrEdtdQb2hWCnswxaAkUunb2qq18vd3dBvlnI+C4/xu5ksZZkRj+fW
+      tArNR18V+2jkwcG26m8AxIrT+m4M6/bgnSfHTBtT5adNfVcTHqiT1JtCbQcXmwVw
+      WbqS6v/LhcsBE//SHne4uBCK/GHxZHhQ5jz5h+3vWeV4gvxS3Xu6v1IlIpLDwUts
+      kT1DumfynYnnZmWTGc6SYyIFXTPJLtnoWDb9OBdWgZxXfHEcBsKGha+bXO+m2tHA
+      gNneN9i5f8oNxo5njrL8jkCckOpNpng18BKXABEBAAG0MlNhbHRTdGFjayBQYWNr
+      YWdpbmcgVGVhbSA8cGFja2FnaW5nQHNhbHRzdGFjay5jb20+iQE4BBMBAgAiBQJT
+      qb6YAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRAOCKFJ3le/vhkqB/0Q
+      WzELZf4d87WApzolLG+zpsJKtt/ueXL1W1KA7JILhXB1uyvVORt8uA9FjmE083o1
+      yE66wCya7V8hjNn2lkLXboOUd1UTErlRg1GYbIt++VPscTxHxwpjDGxDB1/fiX2o
+      nK5SEpuj4IeIPJVE/uLNAwZyfX8DArLVJ5h8lknwiHlQLGlnOu9ulEAejwAKt9CU
+      4oYTszYM4xrbtjB/fR+mPnYh2fBoQO4d/NQiejIEyd9IEEMd/03AJQBuMux62tjA
+      /NwvQ9eqNgLw9NisFNHRWtP4jhAOsshv1WW+zPzu3ozoO+lLHixUIz7fqRk38q8Q
+      9oNR31KvrkSNrFbA3D89uQENBFOpvpgBCADJ79iH10AfAfpTBEQwa6vzUI3Eltqb
+      9aZ0xbZV8V/8pnuU7rqM7Z+nJgldibFk4gFG2bHCG1C5aEH/FmcOMvTKDhJSFQUx
+      uhgxttMArXm2c22OSy1hpsnVG68G32Nag/QFEJ++3hNnbyGZpHnPiYgej3FrerQJ
+      zv456wIsxRDMvJ1NZQB3twoCqwapC6FJE2hukSdWB5yCYpWlZJXBKzlYz/gwD/Fr
+      GL578WrLhKw3UvnJmlpqQaDKwmV2s7MsoZogC6wkHE92kGPG2GmoRD3ALjmCvN1E
+      PsIsQGnwpcXsRpYVCoW7e2nW4wUf7IkFZ94yOCmUq6WreWI4NggRcFC5ABEBAAGJ
+      AR8EGAECAAkFAlOpvpgCGwwACgkQDgihSd5Xv74/NggA08kEdBkiWWwJZUZEy7cK
+      WWcgjnRuOHd4rPeT+vQbOWGu6x4bxuVf9aTiYkf7ZjVF2lPn97EXOEGFWPZeZbH4
+      vdRFH9jMtP+rrLt6+3c9j0M8SIJYwBL1+CNpEC/BuHj/Ra/cmnG5ZNhYebm76h5f
+      T9iPW9fFww36FzFka4VPlvA4oB7ebBtquFg3sdQNU/MmTVV4jPFWXxh4oRDDR+8N
+      1bcPnbB11b5ary99F/mqr7RgQ+YFF0uKRE3SKa7a+6cIuHEZ7Za+zhPaQlzAOZlx
+      fuBmScum8uQTrEF5+Um5zkwC7EXTdH1co/+/V/fpOtxIg4XO4kcugZefVm5ERfVS
+      MA==
+      =dtMN
+      -----END PGP PUBLIC KEY BLOCK-----
+    saltstack_repo_trusty: "http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main"
+    saltstack_repo_xenial: "http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main"
   region:
-    theme: theme
+    theme: mirantis
     bind:
       host: localhost
       port: 80
diff --git a/tests/pillar/postgresql.sls b/tests/pillar/postgresql.sls
new file mode 100644
index 0000000..65bd67e
--- /dev/null
+++ b/tests/pillar/postgresql.sls
@@ -0,0 +1,20 @@
+postgresql:
+  server:
+    enabled: true
+    clients:
+    - 127.0.0.1
+    bind:
+      address: 127.0.0.1
+      port: 5432
+      protocol: tcp
+    database:
+      maasdb:
+        enabled: true
+        encoding: 'UTF8'
+        locale: 'en_US'
+        users:
+        - name: maas
+          password: password
+          host: localhost
+          createdb: true
+          rights: all privileges
diff --git a/tests/pillar/rsyslog.sls b/tests/pillar/rsyslog.sls
new file mode 100644
index 0000000..32c26c1
--- /dev/null
+++ b/tests/pillar/rsyslog.sls
@@ -0,0 +1,13 @@
+rsyslog:
+  #server:
+    #enabled: true
+  client:
+    enabled: true
+    #output:
+      #file:
+        #/var/log/syslog:
+          #filter: "*.*;auth,authpriv.none"
+          #owner: syslog
+          #group: adm
+          #createmode: 0640
+          #umask: 0022
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 9761585..a348912 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -1,5 +1,9 @@
 #!/usr/bin/env bash
 
+###
+# Script requirments:
+#apt-get install -y python-yaml virtualenv git
+
 set -e
 [ -n "$DEBUG" ] && set -x
 
@@ -14,32 +18,40 @@
 VENV_DIR=${VENV_DIR:-${BUILDDIR}/virtualenv}
 MOCK_BIN_DIR=${MOCK_BIN_DIR:-${CURDIR}/mock_bin}
 DEPSDIR=${BUILDDIR}/deps
+SCHEMARDIR=${SCHEMARDIR:-"${CURDIR}/../${FORMULA_NAME}/schemas/"}
 
 SALT_FILE_DIR=${SALT_FILE_DIR:-${BUILDDIR}/file_root}
 SALT_PILLAR_DIR=${SALT_PILLAR_DIR:-${BUILDDIR}/pillar_root}
 SALT_CONFIG_DIR=${SALT_CONFIG_DIR:-${BUILDDIR}/salt}
 SALT_CACHE_DIR=${SALT_CACHE_DIR:-${SALT_CONFIG_DIR}/cache}
+SALT_CACHE_EXTMODS_DIR=${SALT_CACHE_EXTMODS_DIR:-${SALT_CONFIG_DIR}/cache_master_extmods}
 
 SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR} --log-file=/dev/null"
 
+IGNORE_MODELVALIDATE_MASK=${IGNORE_MODELVALIDATE_MASK:-"novalidate"}
+
 if [ "x${SALT_VERSION}" != "x" ]; then
     PIP_SALT_VERSION="==${SALT_VERSION}"
 fi
 
 ## Functions
 log_info() {
-    echo "[INFO] $*"
+    echo -e "[INFO] $*"
 }
 
 log_err() {
-    echo "[ERROR] $*" >&2
+    echo -e "[ERROR] $*" >&2
 }
 
 setup_virtualenv() {
     log_info "Setting up Python virtualenv"
+    dependency_check virtualenv
     virtualenv $VENV_DIR
     source ${VENV_DIR}/bin/activate
     python -m pip install salt${PIP_SALT_VERSION}
+    if [[ -f ${CURDIR}/test-requirements.txt ]]; then
+       python -m pip install -r ${CURDIR}/test-requirements.txt
+    fi
 }
 
 setup_mock_bin() {
@@ -65,6 +77,7 @@
     [ ! -d ${SALT_FILE_DIR} ] && mkdir -p ${SALT_FILE_DIR}
     [ ! -d ${SALT_CONFIG_DIR} ] && mkdir -p ${SALT_CONFIG_DIR}
     [ ! -d ${SALT_CACHE_DIR} ] && mkdir -p ${SALT_CACHE_DIR}
+    [ ! -d ${SALT_CACHE_EXTMODS_DIR} ] && mkdir -p ${SALT_CACHE_EXTMODS_DIR}
 
     echo "base:" > ${SALT_FILE_DIR}/top.sls
     for pillar in ${PILLARDIR}/*.sls; do
@@ -76,6 +89,7 @@
     cat << EOF > ${SALT_CONFIG_DIR}/minion
 file_client: local
 cachedir: ${SALT_CACHE_DIR}
+extension_modules:  ${SALT_CACHE_EXTMODS_DIR}
 verify_env: False
 minion_id_caching: False
 
@@ -83,7 +97,6 @@
   base:
   - ${SALT_FILE_DIR}
   - ${CURDIR}/..
-  - /usr/share/salt-formulas/env
 
 pillar_roots:
   base:
@@ -93,13 +106,14 @@
 }
 
 fetch_dependency() {
+    # example: fetch_dependency "linux:https://github.com/salt-formulas/salt-formula-linux"
     dep_name="$(echo $1|cut -d : -f 1)"
     dep_source="$(echo $1|cut -d : -f 2-)"
     dep_root="${DEPSDIR}/$(basename $dep_source .git)"
     dep_metadata="${dep_root}/metadata.yml"
 
-    [ -d /usr/share/salt-formulas/env/${dep_name} ] && log_info "Dependency $dep_name already present in system-wide salt env" && return 0
-    [ -d $dep_root ] && log_info "Dependency $dep_name already fetched" && return 0
+    dependency_check git
+    [ -d $dep_root ] && { log_info "Dependency $dep_name already fetched"; return 0; }
 
     log_info "Fetching dependency $dep_name"
     [ ! -d ${DEPSDIR} ] && mkdir -p ${DEPSDIR}
@@ -109,6 +123,19 @@
     METADATA="${dep_metadata}" install_dependencies
 }
 
+link_modules(){
+    # Link modules *.py files to temporary salt-root
+    local SALT_ROOT=${1:-$SALT_FILE_DIR}
+    local SALT_ENV=${2:-$DEPSDIR}
+
+    mkdir -p "${SALT_ROOT}/_modules/"
+    # from git, development versions
+    find ${SALT_ENV} -maxdepth 3 -mindepth 3 -path '*_modules*' -iname "*.py" -type f -print0 | while read -d $'\0' file; do
+      ln -fs $(readlink -e ${file}) "$SALT_ROOT"/_modules/$(basename ${file}) ;
+    done
+    salt_run saltutil.sync_all
+}
+
 install_dependencies() {
     grep -E "^dependencies:" ${METADATA} >/dev/null || return 0
     (python - | while read dep; do fetch_dependency "$dep"; done) << EOF
@@ -129,13 +156,30 @@
 }
 
 prepare() {
-    [ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR}
+    if [[ -f ${BUILDDIR}/.prepare_done ]]; then
+      log_info "${BUILDDIR}/.prepare_done exist, not rebuilding BUILDDIR"
+      return
+    fi
+    [[ -d ${BUILDDIR} ]] && mkdir -p ${BUILDDIR}
 
-    which salt-call || setup_virtualenv
+    [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv
     setup_mock_bin
     setup_pillar
     setup_salt
     install_dependencies
+    link_modules
+    touch ${BUILDDIR}/.prepare_done
+}
+
+lint_releasenotes() {
+    [[ ! -f "${VENV_DIR}/bin/activate" ]] && setup_virtualenv
+    source ${VENV_DIR}/bin/activate
+    reno lint ${CURDIR}/../
+}
+
+lint() {
+#    lint_releasenotes
+    log_err "TODO: lint_releasenotes"
 }
 
 run() {
@@ -152,7 +196,7 @@
             meta_name=$(basename ${meta})
             echo "Checking meta ${meta_name} ..."
             salt_run --out=quiet --id=${state_name} cp.get_template ${meta} ${SALT_CACHE_DIR}/${meta_name} \
-              || (log_err "Failed to render meta ${meta} using pillar ${FORMULA_NAME}.${state_name}"; exit 1)
+              || { log_err "Failed to render meta ${meta} using pillar ${FORMULA_NAME}.${state_name}"; exit 1; }
             cat ${SALT_CACHE_DIR}/${meta_name}
         done
     done
@@ -161,10 +205,45 @@
 real_run() {
     for pillar in ${PILLARDIR}/*.sls; do
         state_name=$(basename ${pillar%.sls})
-        salt_run --id=${state_name} state.sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1)
+        salt_run --id=${state_name} state.sls ${FORMULA_NAME} || { log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1; }
     done
 }
 
+run_model_validate(){
+  # Run modelschema.model_validate validation.
+  # TEST iterateble, run for `each formula ROLE against each ROLE_PILLARNAME`
+  # Pillars should be named in conviend ROLE_XXX.sls or ROLE.sls
+  # Example:
+  # client.sls  client_auth.sls  server.sls  server_auth.sls
+  if [ -d ${SCHEMARDIR} ]; then
+    # model validator require py modules
+    fetch_dependency "salt:https://github.com/salt-formulas/salt-formula-salt"
+    link_modules
+    salt_run saltutil.clear_cache; salt_run saltutil.refresh_pillar; salt_run saltutil.sync_all;
+    for role in ${SCHEMARDIR}/*.yaml; do
+      role_name=$(basename "${role%*.yaml}")
+      for pillar in $(ls pillar/${role_name}*.sls | grep -v ${IGNORE_MODELVALIDATE_MASK} ); do
+        pillar_name=$(basename "${pillar%*.sls}")
+        local _message="FORMULA:${FORMULA_NAME} ROLE:${role_name} against PILLAR:${pillar_name}"
+        log_info "model_validate ${_message}"
+        # Rendered Example:
+        # python $(which salt-call) --local -c /test1/maas/tests/build/salt --id=maas_cluster modelschema.model_validate maas cluster
+        salt_run -m ${DEPSDIR}/salt-formula-salt --id=${pillar_name} modelschema.model_validate ${FORMULA_NAME} ${role_name} || { log_err "Execution of model_validate ${_message} failed"; exit 1 ; }
+      done
+    done
+  else
+    log_info "${SCHEMARDIR} not found!";
+  fi
+}
+
+dependency_check() {
+  local DEPENDENCY_COMMANDS=$*
+
+  for DEPENDENCY_COMMAND in $DEPENDENCY_COMMANDS; do
+    which $DEPENDENCY_COMMAND > /dev/null || ( log_err "Command \"$DEPENDENCY_COMMAND\" can not be found in default path."; exit 1; )
+  done
+}
+
 _atexit() {
     RETVAL=$?
     trap true INT TERM EXIT
@@ -187,14 +266,23 @@
     prepare)
         prepare
         ;;
+    lint)
+        lint
+        ;;
     run)
         run
         ;;
     real-run)
         real_run
         ;;
+    model-validate)
+       prepare
+       run_model_validate
+        ;;
     *)
         prepare
+#        lint
         run
+        run_model_validate
         ;;
 esac