Browse Source

Merge pull request #1 from salt-formulas/master

Resyncing with salt-formulas:master
pull/6/head
Farzad Battiwalla 6 years ago
parent
commit
874fee66c9
No account linked to committer's email address
14 changed files with 134 additions and 223 deletions
  1. +0
    -6
      .kitchen.travis.yml
  2. +2
    -2
      .kitchen.yml
  3. +12
    -5
      .travis.yml
  4. +5
    -1
      Makefile
  5. +1
    -1
      debian/control
  6. +1
    -1
      metadata.yml
  7. +1
    -10
      metadata/service/server/cluster.yml
  8. +1
    -7
      metadata/service/server/single.yml
  9. +87
    -0
      mongodb/cluster.sls
  10. +13
    -104
      mongodb/files/mongodb.conf
  11. +2
    -1
      mongodb/init.sls
  12. +6
    -8
      mongodb/map.jinja
  13. +1
    -75
      mongodb/server.sls
  14. +2
    -2
      tests/run_tests.sh

+ 0
- 6
.kitchen.travis.yml View File

@@ -1,6 +0,0 @@
suites:

- name: <%= ENV['SUITE'] %>
provisioner:
pillars-from-files:
mongodb.sls: tests/pillar/<%= ENV['SUITE'] %>.sls

+ 2
- 2
.kitchen.yml View File

@@ -29,9 +29,9 @@ verifier:
sudo: true

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

suites:

+ 12
- 5
.travis.yml View File

@@ -17,17 +17,24 @@ install:
- bundle install

env:
- PLATFORM=trevorj/salty-whales:trusty SUITE=cluster
- PLATFORM=trevorj/salty-whales:xenial SUITE=cluster
- PLATFORM=trevorj/salty-whales:trusty SUITE=single
- PLATFORM=trevorj/salty-whales:xenial SUITE=single
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2016.3 SUITE=cluster
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2016.3 SUITE=single
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7 SUITE=cluster
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2017.7 SUITE=single
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2018.3 SUITE=cluster
- PLATFORM=epcim/salt:saltstack-ubuntu-xenial-salt-2018.3 SUITE=single
# - PLATFORM=epcim/salt:saltstack-ubuntu-bionic-salt-2017.7 SUITE=cluster
# - PLATFORM=epcim/salt:saltstack-ubuntu-bionic-salt-2017.7 SUITE=single
# - PLATFORM=epcim/salt:saltstack-ubuntu-bionic-salt-2018.3 SUITE=cluster
# - PLATFORM=epcim/salt:saltstack-ubuntu-bionic-salt-2018.3 SUITE=single

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

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

notifications:
webhooks:

+ 5
- 1
Makefile View File

@@ -27,6 +27,7 @@ KITCHEN_OPTS_TEST?=""

all:
@echo "make install - Install into DESTDIR"
@echo "make lint - Run lint tests"
@echo "make test - Run tests"
@echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
@echo "make clean - Cleanup after tests run"
@@ -45,6 +46,9 @@ install:
[ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)

lint:
[ ! -d tests ] || (cd tests; ./run_tests.sh lint)

test:
[ ! -d tests ] || (cd tests; ./run_tests.sh)

@@ -65,7 +69,7 @@ release-minor: check-changes
[ ! -f debian/changelog ] || dch -v $(VERSION_MAJOR).$(NEW_MINOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
make genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
(git add -u; git commit -m "Version $(VERSION_MAJOR).$(NEW_MINOR_VERSION)")
git tag -s -m $(NEW_MAJOR_VERSION) $(VERSION_MAJOR).$(NEW_MINOR_VERSION)
git tag -s -m $(VERSION_MAJOR).$(NEW_MINOR_VERSION) $(VERSION_MAJOR).$(NEW_MINOR_VERSION)

check-changes:
@git log --pretty=oneline --decorate $(VERSION)..HEAD | grep -Eqc '.*' || (echo "No new changes since version $(VERSION)"; exit 1)

+ 1
- 1
debian/control View File

@@ -10,6 +10,6 @@ Vcs-Git: https://github.com/tcpcloud/salt-formula-mongodb.git

Package: salt-formula-mongodb
Architecture: all
Depends: ${misc:Depends}, salt-master, reclass
Depends: ${misc:Depends}
Description: MongoDB Salt formula
Install and configure MongoDB server.

+ 1
- 1
metadata.yml View File

@@ -1,3 +1,3 @@
name: "mongodb"
version: "0.2"
source: "https://github.com/tcpcloud/salt-formula-mongodb"
source: "https://github.com/salt-formulas/salt-formula-mongodb"

+ 1
- 10
metadata/service/server/cluster.yml View File

@@ -3,19 +3,10 @@ applications:
classes:
- service.mongodb.support
parameters:
_param:
mongodb_server_replica_set: default
mongodb:
server:
enabled: true
admin:
user: admin
password: ${_param:mongodb_admin_password}
bind:
address: 0.0.0.0
port: 27017
replica_set: ${_param:mongodb_server_replica_set}
shared_key: ${_param:mongodb_shared_key}
members: ${_param:mongodb_server_members}
master: ${_param:mongodb_master}

replica_set: rs0

+ 1
- 7
metadata/service/server/single.yml View File

@@ -6,12 +6,6 @@ parameters:
mongodb:
server:
enabled: true
admin:
user: admin
password: ${_param:mongodb_admin_password}
bind:
address: 0.0.0.0
address: 127.0.0.1
port: 27017
shard_service: False
config_service: False
shared_key: ${_param:mongodb_shared_key}

+ 87
- 0
mongodb/cluster.sls View File

@@ -0,0 +1,87 @@
{%- from "mongodb/map.jinja" import server with context %}

{%- if server.get('enabled', False) %}

mongodb_service_running:
service.running:
- name: {{ server.service }}
- enable: true
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}

{%- if server.members is defined and server.master == pillar.linux.system.name %}

/var/tmp/mongodb_cluster.js:
file.managed:
- source: salt://mongodb/files/cluster.js
- template: jinja
- mode: 600
- user: root
- require:
- service: mongodb_service_running

mongodb_setup_cluster:
cmd.run:
- name: 'mongo localhost:27017 /var/tmp/mongodb_cluster.js && mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
- unless: 'mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
- require:
- service: mongodb_service_running
- file: /var/tmp/mongodb_cluster.js

{%- endif %}

{%- if server.members is not defined or server.master == pillar.linux.system.name %}

{%- if server.authorization.get('enabled', False) %}
/var/tmp/mongodb_user.js:
file.managed:
- source: salt://mongodb/files/user.js
- template: jinja
- mode: 600
- user: root

mongodb_change_root_password:
cmd.run:
- name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: /var/tmp/mongodb_user.js
- service: mongodb_service_running
- creates: {{ server.lock_dir }}/mongodb_password_changed

{%- for database_name, database in server.get('database', {}).iteritems() %}

/var/tmp/mongodb_user_{{ database_name }}.js:
file.managed:
- source: salt://mongodb/files/user_role.js
- template: jinja
- mode: 600
- user: root
- defaults:
database_name: {{ database_name }}

mongodb_{{ database_name }}_fix_role:
cmd.run:
- name: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} /var/tmp/mongodb_user_{{ database_name }}.js && touch {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created'
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: /var/tmp/mongodb_user_{{ database_name }}.js
- service: mongodb_service_running
- creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
{%- if server.members is defined %}
require:
- cmd: mongodb_setup_cluster
{%- endif %}

{%- endfor %}

{%- endif %}

{%- endif %}

{%- endif %}

+ 13
- 104
mongodb/files/mongodb.conf View File

@@ -1,116 +1,25 @@
{%- from "mongodb/map.jinja" import server with context %}

# mongodb.conf

# Where to store the data.
dbpath=/var/lib/mongodb
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

#where to log
logpath=/var/log/mongodb/mongodb.log
port={{ server.bind.port }}
bind_ip={{ server.bind.address }}

logpath=/var/log/mongodb/mongod.log
logappend=true

bind_ip = {{ server.bind.address }}
#port = 27017

# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
dbpath=/var/lib/mongodb
journal=true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

keyFile = /etc/mongodb.key

{%- if server.replica_set is defined %}
replSet = {{ server.replica_set }}
{%- if server.authorization.get('enabled', False) %}
auth=true
{%- endif %}

# Turn on/off security. Off is currently the default
#noauth = true
auth = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true

# Enable db quota management
#quota = true

#OpenStack guide for Juno
smallfiles = true

# Verbose logging output.
verbose = {{ server.logging.get('verbose', False)|lower }}

# logLevel
setParameter = logLevel={{ server.logging.get('logLevel', 1) }}

# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
{%- if server.logging.oplogLevel is defined %}
oplog = {{ server.logging.get('oplogLevel') }}
{%- if server.shared_key is defined %}
keyFile=/etc/mongodb.key
{%- endif %}

# Diagnostic/debugging option
#nocursors = true

# Ignore query hints
#nohints = true

# Disable the HTTP interface (Defaults to localhost:27018).
#nohttpinterface = true

# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true

# Disable data file preallocation.
#noprealloc = true

# Specify .ns file size for new databases.
# nssize = <size>

# Accout token for Mongo monitoring server.
#mms-token = <token>

# Server name for Mongo monitoring server.
#mms-name = <server-name>

# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>

# Replication Options

# in replicated mongo databases, specify here whether this is a slave or master
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com

# Address of a server to pair with.
#pairwith = <server:port>
# Address of arbiter server.
#arbiter = <server:port>
# Automatically resync if slave data is stale
#autoresync
# Custom size for replication operation log.
#oplogSize = <MB>
# Size limit for in-memory storage of op ids.
#opIdMem = <bytes>

# SSL options
# Enable SSL on normal ports
#sslOnNormalPorts = true
# SSL Key file and password
#sslPEMKeyFile = /etc/ssl/mongodb.pem
#sslPEMKeyPassword = pass
{%- if server.replica_set is defined %}
replSet={{ server.replica_set }}
{%- endif %}

+ 2
- 1
mongodb/init.sls View File

@@ -1,4 +1,5 @@
{%- if pillar.mongodb is defined %}
include:
- mongodb.server
{%- endif %}
- mongodb.cluster
{%- endif %}

+ 6
- 8
mongodb/map.jinja View File

@@ -1,30 +1,28 @@
{% set server = salt['grains.filter_by']({
'Debian': {
'pkgs': ['mongodb-server', 'mongodb', 'python-pymongo', 'mongodb-clients'],
'pkgs': ['mongodb-server', 'mongodb', 'mongodb-clients'],
'service': 'mongodb',
'lock_dir': "/var/lock/mongodb",
'logging': {},
'bind': {
'address': '0.0.0.0',
'address': '127.0.0.1',
'port': 27017
},
'config_service': False,
'shard_service': True,
'authorization': {},
'admin': {
'username': 'root'
}
},
'RedHat': {
'pkgs': ['mongodb-server', 'mongodb', 'python-pymongo', 'mongodb-clients'],
'pkgs': ['mongodb-server', 'mongodb', 'mongodb-clients'],
'service': 'mongod',
'lock_dir': "/var/lock/mongodb",
'logging': {},
'bind': {
'address': '0.0.0.0',
'address': '127.0.0.1',
'port': 27017
},
'config_service': False,
'shard_service': True,
'authorization': {},
'admin': {
'username': 'root'
}

+ 1
- 75
mongodb/server.sls View File

@@ -1,6 +1,6 @@
{%- from "mongodb/map.jinja" import server with context %}
{%- if server.enabled %}

{%- if server.get('enabled', False) %}
mongodb_packages:
pkg.installed:
- names: {{ server.pkgs }}
@@ -13,7 +13,6 @@ mongodb_packages:
- pkg: mongodb_packages

{%- if server.shared_key is defined %}

/etc/mongodb.key:
file.managed:
- contents_pillar: mongodb:server:shared_key
@@ -23,7 +22,6 @@ mongodb_packages:
- pkg: mongodb_packages
- watch_in:
- service: mongodb_service

{%- endif %}

{{ server.lock_dir }}:
@@ -43,76 +41,4 @@ mongodb_service:
- watch:
- file: /etc/mongodb.conf

{%- if server.members is not defined or server.master == pillar.linux.system.name %}
{# We are not a cluster or we are master #}

/var/tmp/mongodb_user.js:
file.managed:
- source: salt://mongodb/files/user.js
- template: jinja
- mode: 600
- user: root

mongodb_change_root_password:
cmd.run:
- name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: /var/tmp/mongodb_user.js
- service: mongodb_service
- creates: {{ server.lock_dir }}/mongodb_password_changed

{%- for database_name, database in server.get('database', {}).iteritems() %}

/var/tmp/mongodb_user_{{ database_name }}.js:
file.managed:
- source: salt://mongodb/files/user_role.js
- template: jinja
- mode: 600
- user: root
- defaults:
database_name: {{ database_name }}

mongodb_{{ database_name }}_fix_role:
cmd.run:
- name: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} /var/tmp/mongodb_user_{{ database_name }}.js && touch {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created'
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: /var/tmp/mongodb_user_{{ database_name }}.js
- service: mongodb_service
- creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
{%- if server.members is defined %}
require:
- cmd: mongodb_setup_cluster
{%- endif %}

{%- endfor %}

{%- if server.members is defined %}

/var/tmp/mongodb_cluster.js:
file.managed:
- source: salt://mongodb/files/cluster.js
- template: jinja
- mode: 600
- user: root

mongodb_setup_cluster:
cmd.run:
- name: 'mongo localhost:27017/admin /var/tmp/mongodb_cluster.js && mongo localhost:27017/admin --quiet --eval "rs.conf()" | grep object -q'
- unless: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} --quiet --eval "rs.conf()" | grep object -q'
- require:
- service: mongodb_service
- file: /var/tmp/mongodb_cluster.js
- require_in:
- cmd: mongodb_change_root_password

{%- endif %}

{%- endif %}

{%- endif %}

+ 2
- 2
tests/run_tests.sh View File

@@ -39,7 +39,7 @@ setup_virtualenv() {
log_info "Setting up Python virtualenv"
virtualenv $VENV_DIR
source ${VENV_DIR}/bin/activate
pip install salt${PIP_SALT_VERSION}
python -m pip install salt${PIP_SALT_VERSION}
}

setup_mock_bin() {
@@ -125,7 +125,7 @@ clean() {

salt_run() {
[ -e ${VENV_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
salt-call ${SALT_OPTS} $*
python $(which salt-call) ${SALT_OPTS} $*
}

prepare() {

Loading…
Cancel
Save