Skip to content

Commit

Permalink
Merge pull request #191 from arenadata/develop
Browse files Browse the repository at this point in the history
Release 2020.02.20
  • Loading branch information
acmnu authored Feb 20, 2020
2 parents c4c8b2a + e815152 commit d83bfac
Show file tree
Hide file tree
Showing 203 changed files with 3,162 additions and 479 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM arenadata/adcmbase:20200121195750
FROM arenadata/adcmbase:20200203174702

COPY . /adcm/

RUN cp -r /adcm/os/* / && rm -rf /adcm/os; cp -r /adcm/ansible/* /usr/local/lib/python3.8/site-packages/ansible/ && rm -rf /adcm/ansible && rmdir /var/log/nginx;
RUN cp -r /adcm/os/* / && rm -rf /adcm/os; cp -r /adcm/python/ansible/* /usr/local/lib/python3.8/site-packages/ansible/ && rm -rf /adcm/python/ansible && rmdir /var/log/nginx;

# Secret_key is mandatory for build_static procedure,
# but should not be hardcoded in the image.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Set number of threads
BRANCH_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
ADCMBASE_IMAGE ?= arenadata/adcmbase
ADCMBASE_TAG ?= 20200121195750
ADCMBASE_TAG ?= 20200203174702


# Default target
Expand Down Expand Up @@ -64,4 +64,4 @@ npm_check: ## Run npm-check

django_tests : ## Run django tests.
docker pull $(ADCMBASE_IMAGE):$(ADCMBASE_TAG)
docker run -i --rm -v $(CURDIR)/:/adcm -w /adcm/ $(ADCMBASE_IMAGE):$(ADCMBASE_TAG) python manage.py test cm
docker run -i --rm -v $(CURDIR)/:/adcm -w /adcm/ $(ADCMBASE_IMAGE):$(ADCMBASE_TAG) python python/manage.py test cm
3 changes: 3 additions & 0 deletions conf/nginx/adcm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ server {
root /adcm/wwwroot;

location / {
if ($arg_nocache) {
add_header Cache-Control no-cache;
}
try_files $uri $uri/ /index.html;
}

Expand Down
Binary file added data/download/adb.2.6.tar
Binary file not shown.
Binary file added data/download/ssh.1.3.tar
Binary file not shown.
8 changes: 4 additions & 4 deletions os/etc/service/init/run
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ key=/root/.ssh/id_rsa

if [ ! -f "${adcmroot}"/var/cluster.db ]; then
echo "Assume first run"
"${adcmroot}"/manage.py generate_secret_key "${adcmsecretfile}"
"${adcmroot}"/manage.py migrate
"${adcmroot}"/python/manage.py generate_secret_key "${adcmsecretfile}"
"${adcmroot}"/python/manage.py migrate
else
"${adcmroot}"/manage.py migrate
"${adcmroot}"/python/manage.py migrate
fi

"${adcmroot}"/init_db.py
"${adcmroot}"/python/init_db.py
touch "${initreadyfile}"

# That is sleep forever case because I have no idea how to force
Expand Down
2 changes: 1 addition & 1 deletion os/etc/service/wsgi/run
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ echo "Run main wsgi application ..."
exec 1>"${adcmlog}/service_wsgi.out"
exec 2>"${adcmlog}/service_wsgi.err"

cd "${adcmroot}"
cd "${adcmroot}/python"
uwsgi --socket "${wsgisocketfile}" --pidfile "/run/uwsgi.pid" --module adcm.wsgi --chmod-socket=777 --logger file:logfile="${adcmlog}/wsgi.log",maxsize=2000000
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion adcm/settings.py → python/adcm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

import json
import os
from os.path import dirname

from django.core.management.utils import get_random_secret_key


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
CONF_DIR = BASE_DIR + '/data/conf/'
SECRET_KEY_FILE = CONF_DIR + '/secret_key.txt'
CONFIG_FILE = BASE_DIR + '/config.json'
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase

sys.path.append('/adcm')
sys.path.append('/adcm/python')
import adcm.init_django
import cm.api
from cm.ansible_plugin import get_context_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=wrong-import-position,unused-import
# pylint: disable=wrong-import-position, unused-import, import-error

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'Arenadata'}
Expand Down Expand Up @@ -58,37 +59,51 @@
import sys
from ansible.plugins.action import ActionBase

sys.path.append('/adcm')
sys.path.append('/adcm/python')
import adcm.init_django
import cm.job
from cm.errors import AdcmEx
from cm.logger import log


class ActionModule(ActionBase):

TRANSFERS_FILES = False
_VALID_ARGS = frozenset(('title', 'result', 'msg'))
_VALID_ARGS = frozenset(('title', 'result', 'msg', 'fail_msg', 'success_msg'))

def run(self, tmp=None, task_vars=None):
job_id = None
if task_vars is not None and 'job' in task_vars or 'id' in task_vars['job']:
job_id = task_vars['job']['id']

result = super(ActionModule, self).run(tmp, task_vars)
old_optional_condition = 'msg' in self._task.args
new_optional_condition = 'fail_msg' in self._task.args and 'success_msg' in self._task.args
optional_condition = old_optional_condition or new_optional_condition
required_condition = (
'title' in self._task.args and 'result' in self._task.args and optional_condition
)

if not required_condition:
return {
"failed": True,
"msg": ("title, result and msg, fail_msg or success"
"_msg are mandatory args of adcm_check")
}

if ('title' not in self._task.args or
'result' not in self._task.args or
'msg' not in self._task.args):
return {"failed": True, "msg": "title, result and msg are mandatory args of adcm_check"}
result = super(ActionModule, self).run(tmp, task_vars)
title = self._task.args['title']
result = self._task.args['result']
msg = self._task.args['msg']
msg = self._task.args.get('msg', '')
fail_msg = self._task.args.get('fail_msg', '')
success_msg = self._task.args.get('success_msg', '')

log.debug('ansible adcm_check: %s, %s, %s, %s', job_id, title, result, msg)
log.debug('ansible adcm_check: %s, %s, %s, %s, %s, %s',
job_id, title, result, msg, fail_msg, success_msg)

try:
if result:
msg = success_msg if success_msg else msg
else:
msg = fail_msg if fail_msg else msg
cm.job.log_check(job_id, title, result, msg)
except AdcmEx as e:
return {"failed": True, "msg": e.code + ":" + e.msg}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__metaclass__ = type

import sys
sys.path.append('/adcm')
sys.path.append('/adcm/python')

import adcm.init_django
from cm.ansible_plugin import ContextActionModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase

sys.path.append('/adcm')
sys.path.append('/adcm/python')
import adcm.init_django
import cm.api
from cm.ansible_plugin import get_context_id
Expand Down
66 changes: 66 additions & 0 deletions python/ansible/plugins/action/adcm_delete_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=wrong-import-position,unused-import

from __future__ import absolute_import, division, print_function
__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'Arenadata'}

DOCUMENTATION = r'''
---
module: adcm_delete_service
short_description: delete service from cluster in ADCM DB
description:
- The C(adcm_delete_service) module is intended to delete service from ADCM DB.
This module should be run in service context. Service Id is taken from context.
options:
'''

EXAMPLES = r'''
- name: delete service from cluster
adcm_delete_service:
'''

RETURN = r'''
'''

import sys
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase

sys.path.append('/adcm/python')
import adcm.init_django
import cm.api
from cm.ansible_plugin import get_context_id
from cm.errors import AdcmEx
from cm.logger import log


class ActionModule(ActionBase):

TRANSFERS_FILES = False
_VALID_ARGS = frozenset(())

def run(self, tmp=None, task_vars=None):
msg = 'You can delete service only in service context'
service_id = get_context_id(task_vars, 'service', 'service_id', msg)
log.info('ansible module adcm_delete_service: service #%s', service_id)

try:
cm.api.delete_service_by_id(service_id)
except AdcmEx as e:
raise AnsibleError(e.code + ":" + e.msg)

return {"failed": False, "changed": True}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
__metaclass__ = type

import sys
sys.path.append('/adcm')
sys.path.append('/adcm/python')
import adcm.init_django

from cm.ansible_plugin import ContextActionModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ansible.utils.display import Display # pylint: disable=ungrouped-imports
display = Display()

sys.path.append('/adcm')
sys.path.append('/adcm/python')
import adcm.init_django
import cm.adcm_config
from cm.logger import log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
display = Display()

import sys
sys.path.append('/adcm')
sys.path.append('/adcm/python')
import adcm.init_django
import cm.api
import cm.status_api
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions api/cluster_serial.py → python/api/cluster_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,15 @@ def get_kwargs(self, obj):

id = serializers.IntegerField(read_only=True)
name = serializers.SerializerMethodField()
component_prototype_id = serializers.SerializerMethodField()
prototype_id = serializers.SerializerMethodField()
display_name = serializers.SerializerMethodField()
description = serializers.SerializerMethodField()
url = MyUrlField(read_only=True, view_name='service-component-details')

def get_name(self, obj):
return obj.component.name

def get_component_prototype_id(self, obj):
def get_prototype_id(self, obj):
return obj.component.id

def get_display_name(self, obj):
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions api/serializers.py → python/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,15 @@ class ProviderActionShort(ActionShort):
class UpgradeSerializer(serializers.Serializer):
id = serializers.IntegerField(read_only=True)
name = serializers.CharField(required=False)
bundle_id = serializers.IntegerField(read_only=True)
description = serializers.CharField(required=False)
min_version = serializers.CharField(required=False)
max_version = serializers.CharField(required=False)
min_strict = serializers.BooleanField(required=False)
max_strict = serializers.BooleanField(required=False)
upgradable = serializers.BooleanField(required=False)
license = serializers.CharField(required=False)
license_url = hlink('bundle-license', 'bundle_id', 'bundle_id')
from_edition = JSONField(required=False)
state_available = JSONField(required=False)
state_on_success = serializers.CharField(required=False)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% load staticfiles %}
{% load static %}

{% include "docs-md/document.md" %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions cm/api.py → python/cm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,33 @@ def delete_host(host):


def delete_host_by_id(host_id):
"""
Host deleting
This is intended for use in adcm_delete_host ansible plugin
"""
try:
host = Host.objects.get(id=host_id)
except Host.DoesNotExist:
err('HOST_NOT_FOUND', 'Host with id #{} is not found'.format(host_id))
delete_host(host)


def delete_service_by_id(service_id):
"""
Unconditional removal of service from cluster
This is intended for use in adcm_delete_service ansible plugin
"""
try:
service = ClusterObject.objects.get(id=service_id)
except ClusterObject.DoesNotExist:
err('SERVICE_NOT_FOUND', 'Service with id #{} is not found'.format(service_id))
cm.status_api.post_event('delete', 'service', service.id)
service.delete()
cm.status_api.load_service_map()


def delete_service(service):
if HostComponent.objects.filter(cluster=service.cluster, service=service):
err('SERVICE_CONFLICT', 'Service #{} has component(s) on host(s)'.format(service.id))
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions cm/config.py → python/cm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@

import json
import os
from os.path import dirname


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
BASE_DIR = os.environ.get('ADCM_BASE_DIR', BASE_DIR)

STACK_DIR = BASE_DIR
STACK_DIR = os.environ.get('ADCM_STACK_DIR', STACK_DIR)

CODE_DIR = os.path.join(BASE_DIR, 'python')

LOG_DIR = os.path.join(BASE_DIR, 'data', 'log')
RUN_DIR = os.path.join(BASE_DIR, 'data', 'run')

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions cm/inventory.py → python/cm/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ def get_provider_hosts(provider_id):

def get_host(host_id):
host = Host.objects.get(id=host_id)
groups = {'HOST': {'hosts': get_hosts([host])}}
groups.update(get_provider_hosts(host.provider.id))
groups['PROVIDER']['vars'] = get_provider_config(host.provider.id)
groups = {'HOST': {
'hosts': get_hosts([host]),
'vars': get_provider_config(host.provider.id)
}}
return groups


Expand Down
File renamed without changes.
Loading

0 comments on commit d83bfac

Please sign in to comment.