Merge "Optimize kitchen tests for Travis CI"
diff --git a/README.rst b/README.rst
index cafb41c..1449ee1 100644
--- a/README.rst
+++ b/README.rst
@@ -420,6 +420,23 @@
         cpu:
           governor: performance
 
+
+Shared Libraries
+~~~~~~~~~~~~~~~~
+
+Set additional shared library to Linux system library path
+
+.. code-block:: yaml
+
+    linux:
+      system:
+        ld:
+          library:
+            java:
+              - /usr/lib/jvm/jre-openjdk/lib/amd64/server
+              - /opt/java/jre/lib/amd64/server
+    
+
 Certificates
 ~~~~~~~~~~~~
 
@@ -1437,7 +1454,7 @@
                   mount: ${linux:storage:mount:data}
 
 Create partitions on disk. Specify size in MB. It expects empty
-disk without any existing partitions.
+disk without any existing partitions. (set startsector=1, if you want to start partitions from 2048)
 
 .. code-block:: yaml
 
@@ -1445,6 +1462,7 @@
         storage:
           disk:
             first_drive:
+              startsector: 1
               name: /dev/loop1
               type: gpt
               partitions:
diff --git a/linux/files/60-net-txqueue.rules b/linux/files/60-net-txqueue.rules
index 7805c9c..8f6478c 100644
--- a/linux/files/60-net-txqueue.rules
+++ b/linux/files/60-net-txqueue.rules
@@ -1 +1 @@
-KERNEL==”tap[0-9a-z\-]*", RUN+="/sbin/ip link set %k txqueuelen {{ network.tap_custom_txqueuelen }}"
\ No newline at end of file
+KERNEL=="tap[0-9a-z\-]*", RUN+="/sbin/ip link set %k txqueuelen {{ tap_custom_txqueuelen }}"
diff --git a/linux/map.jinja b/linux/map.jinja
index c623d63..29dba83 100644
--- a/linux/map.jinja
+++ b/linux/map.jinja
@@ -117,6 +117,9 @@
     'hashing-algorithm',
     'hardware-dma-ring-rx',
     'hwaddr',
+    'noifupdown',
+    'arp_ip_target',
+    'primary',
 ] %}
 
 {% set network = salt['grains.filter_by']({
diff --git a/linux/meta/fluentd.yml b/linux/meta/fluentd.yml
index c2e5b77..6b4041c 100644
--- a/linux/meta/fluentd.yml
+++ b/linux/meta/fluentd.yml
@@ -1,41 +1,47 @@
-config:
-  label:
-    systemd:
-      input:
-        systemd:
-          type: systemd
-          tag: systemd.source
-          path: /run/log/journal
-          pos_file: /var/log/td-agent/tmp/systemd.source.pos
-          entry:
-            field_map:
-              MESSAGE: 'Payload'
-              _CMDLINE: 'process'
-              _PID: 'Pid'
-              _COMM: 'programname'
-              _SYSTEMD_UNIT: 'service'
-              syslog_identifier: 'ident'
-              priority: 'Severity'
-            field_map_strict: True
-            fields_strip_underscores: True
-            fields_lowercase: True
-      filter:
-        add_severity_label:
-          tag: systemd.source
-          type: record_transformer
-          enable_ruby: true
-          record:
-            - name: severity_label
-              value: '${ {"TRACE"=>8,"DEBUG"=>7,"INFO"=>6,"NOTICE"=>5,"WARNING"=>4,"ERROR"=>3,"CRITICAL"=>2,"ALERT"=>1,"EMERGENCY"=>0}.key(record["Severity"].to_i) }'
-      match:
-        rewrite_tag:
-          tag: systemd.source
-          type: rewrite_tag_filter
-          rule:
-            - name: service
-              regexp: '^(.*)\.(.*)$'
-              result: __TAG__.$1
-        push_to_default:
-          tag: 'systemd.source.*'
-          type: relabel
-          label: default_output
+{%- if grains.get('init') == 'systemd' %}
+agent:
+  plugin:
+    fluent-plugin-systemd:
+      gem: ['fluent-plugin-systemd']
+  config:
+    label:
+      systemd:
+        input:
+          systemd:
+            type: systemd
+            tag: systemd.source
+            path: /run/log/journal
+            pos_file: {{ pillar.fluentd.agent.dir.positiondb }}/systemd.source.pos
+            entry:
+              field_map:
+                MESSAGE: 'Payload'
+                _CMDLINE: 'process'
+                _PID: 'Pid'
+                _COMM: 'programname'
+                _SYSTEMD_UNIT: 'service'
+                syslog_identifier: 'ident'
+                priority: 'Severity'
+              field_map_strict: True
+              fields_strip_underscores: True
+              fields_lowercase: True
+        filter:
+          add_severity_label:
+            tag: systemd.source
+            type: record_transformer
+            enable_ruby: true
+            record:
+              - name: severity_label
+                value: '${ {"TRACE"=>8,"DEBUG"=>7,"INFO"=>6,"NOTICE"=>5,"WARNING"=>4,"ERROR"=>3,"CRITICAL"=>2,"ALERT"=>1,"EMERGENCY"=>0}.key(record["Severity"].to_i) }'
+        match:
+          rewrite_tag:
+            tag: systemd.source
+            type: rewrite_tag_filter
+            rule:
+              - name: service
+                regexp: '^(.*)\.(.*)$'
+                result: __TAG__.$1
+          push_to_default:
+            tag: 'systemd.source.*'
+            type: relabel
+            label: default_output
+{%- endif %}
diff --git a/linux/meta/prometheus.yml b/linux/meta/prometheus.yml
index bea6995..e8a26e3 100644
--- a/linux/meta/prometheus.yml
+++ b/linux/meta/prometheus.yml
@@ -14,6 +14,7 @@
     SystemDiskSpaceTooLow:
       if: 'predict_linear(disk_free[1h], 8*3600) < 0'
       {% raw %}
+      for: 15m
       labels:
         severity: warning
         service: system
@@ -21,6 +22,16 @@
         summary: 'Free space for {{ $labels.path }} too low on {{ $labels.host }}'
         description: 'The disk partition ({{ $labels.path }}) will be full in less than 8 hours on {{ $labels.host }}.'
       {% endraw %}
+    SystemFreeOpenFilesTooLow:
+      if: 'predict_linear(linux_sysctl_fs_file_nr[1h], 8*3600) > linux_sysctl_fs_file_max'
+      {% raw %}
+      labels:
+        severity: warning
+        service: system
+      annotations:
+        summary: 'Free open files for {{ $labels.path }} too low on {{ $labels.host }}'
+        description: 'Host {{ $labels.host }}) will run out of free open files in less than 8 hours.'
+      {% endraw %}
     SystemDiskSpaceFull:
       if: 'disk_used_percent >= 99 and disk_inodes_total > 0'
       {% raw %}
@@ -34,6 +45,7 @@
     SystemDiskInodesTooLow:
       if: 'predict_linear(disk_inodes_free[1h], 8*3600) < 0'
       {% raw %}
+      for: 15m
       labels:
         severity: warning
         service: system
diff --git a/linux/meta/salt.yml b/linux/meta/salt.yml
index 9ca9ee9..20c9be9 100644
--- a/linux/meta/salt.yml
+++ b/linux/meta/salt.yml
@@ -12,9 +12,12 @@
     {%- for service_name, service in pillar.items() %}
       {%- if service.get('_support', {}).get('sphinx', {}).get('enabled', False) %}
         {%- set grains_fragment_file = service_name+'/meta/sphinx.yml' %}
-        {%- macro load_grains_file() %}{% include grains_fragment_file %}{% endmacro %}
-        {%- set grains_yaml = load_grains_file()|load_yaml %}
-        {%- do service_grains.sphinx.doc.update({ service_name: grains_yaml.doc }) %}
+        {%- macro load_grains_file() %}{% include grains_fragment_file ignore missing %}{% endmacro %}
+        {%- set grains = load_grains_file()|load_yaml %}
+        {%- if grains %}
+          {%- set grains_yaml = load_grains_file()|load_yaml %}
+          {%- do service_grains.sphinx.doc.update({ service_name: grains_yaml.doc }) %}
+        {%- endif %}
       {%- endif %}
     {%- endfor %}
     {{ service_grains|yaml(False)|indent(4) }}
diff --git a/linux/meta/telegraf.yml b/linux/meta/telegraf.yml
index 693638b..45fef5c 100644
--- a/linux/meta/telegraf.yml
+++ b/linux/meta/telegraf.yml
@@ -22,3 +22,4 @@
     processes:
     swap:
     system:
+    linux_sysctl_fs:
diff --git a/linux/network/dhclient.sls b/linux/network/dhclient.sls
index 6de2cfd..c0b007b 100644
--- a/linux/network/dhclient.sls
+++ b/linux/network/dhclient.sls
@@ -8,4 +8,11 @@
     - source: salt://linux/files/dhclient.conf
     - template: jinja
 
+{%- elif network.dhclient.enabled is defined and network.dhclient.enabled == False %}
+
+kill_dhcp_client:
+  cmd.run:
+  - name: "pkill dhclient"
+  - onlyif: "pgrep dhclient"
+
 {%- endif %}
diff --git a/linux/network/dpdk.sls b/linux/network/dpdk.sls
index 751941c..1ac9e25 100644
--- a/linux/network/dpdk.sls
+++ b/linux/network/dpdk.sls
@@ -55,6 +55,10 @@
 ]
 %}
 
+{%- if network.openvswitch.get('vhost_socket_dir',{}).get('path') %}
+{%- do ovs_options.append("vhost-sock-dir=\""+network.openvswitch.vhost_socket_dir.path+"\"") %}
+{%- endif %}
+
 {%- for option in ovs_options %}
 
 linux_network_dpdk_ovs_option_{{ option }}:
diff --git a/linux/network/interface.sls b/linux/network/interface.sls
index 6f37348..921ceac 100644
--- a/linux/network/interface.sls
+++ b/linux/network/interface.sls
@@ -45,6 +45,13 @@
 
 {%- endfor %}
 
+{%- if network.interface is defined %}
+
+remove_cloud_init_file:
+  file.absent:
+  - name: /etc/network/interfaces.d/50-cloud-init.cfg
+
+{%- endif %}
 
 {%- for interface_name, interface in network.interface.iteritems() %}
 
@@ -121,7 +128,7 @@
 ovs_port_{{ interface_name }}_line1:
   file.replace:
   - name: /etc/network/interfaces
-  - pattern: auto {{ interface_name }}
+  - pattern: auto {{ interface_name }}$
   - repl: ""
 
 ovs_port_{{ interface_name }}_line2:
@@ -218,7 +225,7 @@
 
 linux_interface_ipflush_onchange_{{ interface_name }}:
   cmd.run:
-  - name: "/sbin/ip address flush dev {{ interface_name }}"
+  - name: "/sbin/ip address flush dev {{ interface_name }}; ifdown {{ interface_name }} ;ifup {{ interface_name }};"
   - onchanges:
     - network: linux_interface_{{ interface_name }}
 
@@ -246,7 +253,7 @@
 remove_interface_{{ network }}_line1:
   file.replace:
   - name: /etc/network/interfaces
-  - pattern: auto {{ network }}
+  - pattern: auto {{ network }}$
   - repl: ""
 
 remove_interface_{{ network }}_line2:
@@ -346,6 +353,14 @@
       # Workaround for Upstream-Bug: https://github.com/saltstack/salt/issues/40262
       source /etc/network/interfaces.u/*
 
+linux_interfaces_final_include_no_requisite:
+  file.prepend:
+  - name: /etc/network/interfaces
+  - text: |
+      source /etc/network/interfaces.d/*
+      # Workaround for Upstream-Bug: https://github.com/saltstack/salt/issues/40262
+      source /etc/network/interfaces.u/*
+
 {%- endif %}
 
 {%- endif %}
@@ -365,5 +380,19 @@
   - source: salt://linux/files/60-net-txqueue.rules
   - mode: 755
   - template: jinja
+  - defaults:
+    tap_custom_txqueuelen: {{ network.tap_custom_txqueuelen }}
+
+udev_reload_rules:
+  cmd.run:
+  - name: "/bin/udevadm control --reload-rules"
+  - onchanges:
+    - file: /etc/udev/rules.d/60-net-txqueue.rules
+
+udev_retrigger:
+  cmd.run:
+  - name: "/bin/udevadm trigger --attr-match=subsystem=net"
+  - onchanges:
+    - udev_reload_rules
 
 {%- endif %}
diff --git a/linux/storage/disk.sls b/linux/storage/disk.sls
index 4fc96e5..493b8df 100644
--- a/linux/storage/disk.sls
+++ b/linux/storage/disk.sls
@@ -20,6 +20,9 @@
     - pkg: parted
 
 {% set end_size = 0 -%}
+{% if disk.get('startsector', None) %}
+{% set end_size = disk.get('startsector')|int %}
+{% endif %}
 
 {%- for partition in disk.get('partitions', []) %}
 
@@ -28,7 +31,9 @@
   - name: partition.mkpart
   - device: {{ disk_name }}
   - part_type: primary
+  {%- if partition.type is defined %}
   - fs_type: {{ partition.type }}
+  {%- endif %}
   - start: {{ end_size }}MB
   - end: {{ end_size + partition.size }}MB
   - unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }}"
diff --git a/linux/storage/lvm.sls b/linux/storage/lvm.sls
index e88c2f1..2a0a67c 100644
--- a/linux/storage/lvm.sls
+++ b/linux/storage/lvm.sls
@@ -5,6 +5,23 @@
   pkg.installed:
   - pkgs: {{ storage.lvm_pkgs }}
 
+
+/etc/lvm/lvm.conf:
+  file.managed:
+  - source: salt://linux/files/lvm.conf
+  - template: jinja
+  - require:
+    - pkg: linux_lvm_pkgs
+
+lvm_services:
+  service.running:
+  - enable: true
+  - names: {{ storage.lvm_services }}
+  - require:
+    - file: /etc/lvm/lvm.conf
+  - watch:
+    - file: /etc/lvm/lvm.conf
+
 {%- for vgname, vg in storage.lvm.iteritems() %}
 
 {%- if vg.get('enabled', True) %}
@@ -15,6 +32,8 @@
     - name: {{ dev }}
     - require:
       - pkg: linux_lvm_pkgs
+      - file: /etc/lvm/lvm.conf
+      - service: lvm_services
     - require_in:
       - lvm: lvm_vg_{{ vg.get('name', vgname) }}
 {%- endfor %}
@@ -47,20 +66,4 @@
 
 {%- endfor %}
 
-/etc/lvm/lvm.conf:
-  file.managed:
-  - source: salt://linux/files/lvm.conf
-  - template: jinja
-  - require:
-    - pkg: linux_lvm_pkgs
-
-lvm_services:
-  service.running:
-  - enable: true
-  - names: {{ storage.lvm_services }}
-  - require:
-    - file: /etc/lvm/lvm.conf
-  - watch:
-    - file: /etc/lvm/lvm.conf
-
-{%- endif %}
+{%- endif %}
\ No newline at end of file
diff --git a/linux/storage/mount.sls b/linux/storage/mount.sls
index af77c26..90e9bd1 100644
--- a/linux/storage/mount.sls
+++ b/linux/storage/mount.sls
@@ -10,7 +10,7 @@
 mkfs_{{ mount.device}}:
   cmd.run:
   - name: "mkfs.{{ mount.file_system }} -L {{ name }} {{ mount.device }}"
-  - onlyif: "test `blkid {{ mount.device }} >/dev/null;echo $?` -eq 2"
+  - onlyif: "test `blkid {{ mount.device }} | grep -q TYPE;echo $?` -eq 1"
   - require_in:
     - mount: {{ mount.path }}
   {%- if mount.file_system == 'xfs' %}
diff --git a/linux/system/apt.sls b/linux/system/apt.sls
index 938bc8b..dca8135 100644
--- a/linux/system/apt.sls
+++ b/linux/system/apt.sls
@@ -9,9 +9,9 @@
 
 {%- for key, config in system.apt.get('config', {}).iteritems() %}
 
-linux_apt_conf_{{ key }}
+linux_apt_conf_{{ key }}:
   file.managed:
-  - name: /etc/apt/apt.conf.d/99{{ key }}-salt:
+  - name: /etc/apt/apt.conf.d/99{{ key }}-salt
   - template: jinja
   - source: salt://linux/files/apt.conf
   - defaults:
diff --git a/linux/system/grub.sls b/linux/system/grub.sls
index e7e1f8c..74ea553 100644
--- a/linux/system/grub.sls
+++ b/linux/system/grub.sls
@@ -6,8 +6,22 @@
     - mode: 755
     - makedirs: True
 
+{%- if grains['os_family'] == 'RedHat' %}
+/etc/default/grub:
+  file.append:
+    - text:
+      - for i in $(ls /etc/default/grub.d);do source /etc/default/grub.d/$i ;done
+
+grub_update:
+  cmd.wait:
+  - name: grub2-mkconfig -o /boot/grub2/grub.cfg
+
+{%- else %}
+
 {%- if grains.get('virtual_subtype', None) not in ['Docker', 'LXC'] %}
 grub_update:
   cmd.wait:
   - name: update-grub
 {%- endif %}
+
+{%- endif %}
diff --git a/linux/system/init.sls b/linux/system/init.sls
index e17adc5..25008a8 100644
--- a/linux/system/init.sls
+++ b/linux/system/init.sls
@@ -99,6 +99,9 @@
 {%- if system.directory is defined %}
 - linux.system.directory
 {%- endif %}
+{%- if system.ld is defined %}
+- linux.system.ld
+{%- endif %}
 {%- if system.apt is defined and grains.os_family == 'Debian' %}
 - linux.system.apt
 {%- endif %}
diff --git a/linux/system/kernel.sls b/linux/system/kernel.sls
index e3e6bd1..59b7177 100644
--- a/linux/system/kernel.sls
+++ b/linux/system/kernel.sls
@@ -3,11 +3,13 @@
 
 {%- if system.kernel is defined %}
 
-{%- if system.kernel.isolcpu is defined %}
+{%- if system.kernel.isolcpu is defined or system.kernel.elevator is defined %}
 
 include:
   - linux.system.grub
 
+{%- if system.kernel.isolcpu is defined %}
+
 /etc/default/grub.d/90-isolcpu.cfg:
   file.managed:
     - contents: 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT isolcpus={{ system.kernel.isolcpu }}"'
@@ -20,6 +22,22 @@
 {%- endif %}
 {%- endif %}
 
+{%- if system.kernel.elevator is defined %}
+
+/etc/default/grub.d/91-elevator.cfg:
+  file.managed:
+    - contents: 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT elevator={{ system.kernel.elevator }}"'
+    - require:
+      - file: grub_d_directory
+{%- if grains.get('virtual_subtype', None) not in ['Docker', 'LXC'] %}
+    - watch_in:
+      - cmd: grub_update
+
+{%- endif %}
+{%- endif %}
+
+{%- endif %}
+
 {%- if system.kernel.version is defined %}
 
 linux_kernel_package:
diff --git a/linux/system/ld.sls b/linux/system/ld.sls
new file mode 100644
index 0000000..fb239da
--- /dev/null
+++ b/linux/system/ld.sls
@@ -0,0 +1,23 @@
+{%- from "linux/map.jinja" import system with context %}
+
+{%- if system.enabled %}
+
+{%- for key in system.ld.library %}
+/etc/ld.so.conf.d/{{ key }}.conf:
+  file.managed:
+    - user: root
+    - group: root
+    - mode: 644
+    - contents: |
+          {% for val in system.ld.library[key] -%}
+          {{ val }}
+          {% endfor %}
+    - watch_in:
+      - cmd: ldconfig_update
+{% endfor %}
+
+ldconfig_update:
+  cmd.wait:
+  - name: ldconfig
+
+{% endif %}
diff --git a/tests/pillar/network_extended.sls b/tests/pillar/network_extended.sls
index 19587c9..e0e428d 100644
--- a/tests/pillar/network_extended.sls
+++ b/tests/pillar/network_extended.sls
@@ -8,6 +8,7 @@
     hostname: linux
     fqdn: linux.ci.local
     network_manager: false
+    tap_custom_txqueuelen: 10000
     interface:
       eth0:
         enabled: true
diff --git a/tests/pillar/network_openvswitch_dpdk.sls b/tests/pillar/network_openvswitch_dpdk.sls
index fa96cb9..d4e6785 100644
--- a/tests/pillar/network_openvswitch_dpdk.sls
+++ b/tests/pillar/network_openvswitch_dpdk.sls
@@ -16,6 +16,9 @@
       dpdk_socket_mem: "1024"
       dpdk_lcore_mask: "0x400"
       memory_channels: "2"
+      vhost_socket_dir:
+        name: "openvswitch-vhost"
+        path: "/run/openvswitch-vhost"
     interface:
       dpdk0:
         name: enp5s0f1
diff --git a/tests/pillar/system.sls b/tests/pillar/system.sls
index cba1aea..06a1bdc 100644
--- a/tests/pillar/system.sls
+++ b/tests/pillar/system.sls
@@ -18,6 +18,7 @@
       default: "linux.ci.local$"
     kernel:
       isolcpu: 1,2,3,4
+      elevator: deadline
     sysfs:
       scheduler:
         block/sda/queue/scheduler: deadline
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 3f42101..9451611 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -110,7 +110,7 @@
 }
 
 salt_run() {
-    [ -e ${VEN_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
+    [ -e ${VENV_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
     salt-call ${SALT_OPTS} $*
 }