Browse Source

Cherry-picked changes from release-0.3

* Resolved PEP8 issues
* Improved RabbitMQ connection handling, updated requirements and README file
* MANIFEST.in file added + formatting
* Add installer and init.d scripts
* version bump to 0.3

Change-Id: Ieca65706da2e3d25ffc0801eabab5905945dab28
Serg Melikyan 5 years ago
parent
commit
482f83ef32

+ 3
- 0
python-agent/MANIFEST.in View File

@@ -0,0 +1,3 @@
1
+include requirements.txt
2
+prune windows-agent
3
+prune python-agent

+ 10
- 0
python-agent/README.rst View File

@@ -0,0 +1,10 @@
1
+Murano Python Agent README
2
+==========================
3
+Murano Python Agent is a VM-side guest agent that accepts commands from
4
+Murano Conductor and executes them. Python Agent works on Linux and
5
+uses new execution plan format described in `Unified Agent blueprint
6
+<https://wiki.openstack.org/wiki/Murano/UnifiedAgent>`_
7
+
8
+SEE ALSO
9
+--------
10
+* `Murano <https://wiki.openstack.org/wiki/Murano>`__

+ 2
- 2
python-agent/etc/agent.conf View File

@@ -1,8 +1,8 @@
1 1
 [DEFAULT]
2 2
 debug=True
3 3
 verbose=True
4
-
5
-storage=.
4
+log_file = /var/log/murano-agent.log
5
+storage=/var/murano/plans
6 6
 
7 7
 [rabbitmq]
8 8
 

+ 103
- 0
python-agent/init.d/murano-agent-deb View File

@@ -0,0 +1,103 @@
1
+#!/bin/sh
2
+#    Copyright (c) 2013 Mirantis, Inc.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+#    Author: Igor Yozhikov <iyozhikov@mirantis.com>
16
+#
17
+### BEGIN INIT INFO
18
+# Provides:          murano-agent
19
+# Required-Start:    $network $local_fs $remote_fs $syslog
20
+# Required-Stop:     $remote_fs
21
+# Default-Start:     2 3 4 5
22
+# Default-Stop:      0 1 6
23
+# Short-Description: Launches the murano linux agent
24
+# Description:       This startup script launches murano linux agent.
25
+### END INIT INFO
26
+
27
+
28
+PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
29
+DESC="murano-agent"
30
+NAME=murano-agent
31
+DAEMON=/usr/local/bin/muranoagent
32
+PIDFILE=/var/run/$NAME.pid
33
+SCRIPTNAME=/etc/init.d/$NAME
34
+SYSTEM_USER=root
35
+CONFIG_FILE=/etc/murano/agent.conf
36
+DATADIR=/var/murano/plans
37
+
38
+# Exit if the package is not installed
39
+[ -x $DAEMON ] || exit 5
40
+
41
+# source function library
42
+. /lib/lsb/init-functions
43
+
44
+if [ ! -d "$DATADIR" ]; then
45
+        mkdir -p ${DATADIR}
46
+        chown ${SYSTEM_USER} ${DATADIR}
47
+fi
48
+
49
+do_start () {
50
+        start-stop-daemon --start --background --quiet --chuid $SYSTEM_USER:$SYSTEM_USER --make-pidfile --pidfile $PIDFILE --startas $DAEMON --test -- --config-file=$CONFIG_FILE > /dev/null || return 1
51
+        start-stop-daemon --start --background --quiet --chuid $SYSTEM_USER:$SYSTEM_USER --make-pidfile --pidfile $PIDFILE --startas $DAEMON -- --config-file=$CONFIG_FILE || return 2
52
+}
53
+
54
+do_stop () {
55
+        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
56
+        RETVAL="$?"
57
+        rm -f $PIDFILE
58
+        return "$RETVAL"
59
+}
60
+
61
+case "$1" in
62
+  start)
63
+    log_daemon_msg "Starting $DESC" "$NAME"
64
+    do_start
65
+    case "$?" in
66
+                0|1) log_end_msg 0 ;;
67
+                2) log_end_msg 1 ;;
68
+        esac
69
+  ;;
70
+  stop)
71
+        log_daemon_msg "Stopping $DESC" "$NAME"
72
+        do_stop
73
+        case "$?" in
74
+                0|1) log_end_msg 0 ;;
75
+                2) log_end_msg 1 ;;
76
+        esac
77
+        ;;
78
+  status)
79
+       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
80
+       ;;
81
+  restart|force-reload)
82
+        log_daemon_msg "Restarting $DESC" "$NAME"
83
+        do_stop
84
+        case "$?" in
85
+          0|1)
86
+                do_start
87
+                case "$?" in
88
+                        0) log_end_msg 0 ;;
89
+                        1) log_end_msg 1 ;; # Old process is still running
90
+                        *) log_end_msg 1 ;; # Failed to start
91
+                esac
92
+                ;;
93
+          *)
94
+                # Failed to stop
95
+                log_end_msg 1
96
+                ;;
97
+        esac
98
+        ;;
99
+  *)
100
+        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
101
+        exit 3
102
+        ;;
103
+esac

+ 103
- 0
python-agent/init.d/murano-agent-el6 View File

@@ -0,0 +1,103 @@
1
+#!/bin/sh
2
+#    Copyright (c) 2013 Mirantis, Inc.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+#    Author: Igor Yozhikov <iyozhikov@mirantis.com>
16
+#
17
+### BEGIN INIT INFO
18
+# Provides: murano-agent
19
+# Required-Start:    $network $local_fs $remote_fs $syslog
20
+# Required-Stop:     $remote_fs
21
+# Default-Start:     2 3 4 5
22
+# Default-Stop:      0 1 6
23
+# Short-Description: Launches the murano linux agent
24
+# Description: This startup script launches murano linux agent.
25
+### END INIT INFO
26
+# chkconfig: 3 90 10
27
+# description: This startup script launches the murano linux agent.
28
+# config: /etc/murano/agent.conf
29
+#
30
+PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
31
+DESC="murano-agent"
32
+NAME=murano-agent
33
+DAEMON=/usr/local/bin/muranoagent
34
+PIDFILE=/var/run/$NAME.pid
35
+SCRIPTNAME=/etc/init.d/$NAME
36
+SYSTEM_USER=root
37
+CONFIG_FILE=/etc/murano/agent.conf
38
+DATADIR=/var/murano/plans
39
+LOCKFILE=/var/lock/subsys/$NAME
40
+# Exit if the package is not installed
41
+[ -x $DAEMON ] || exit 5
42
+
43
+# source function library
44
+. /etc/init.d/functions
45
+
46
+RETVAL=0
47
+
48
+if [ ! -d "$DATADIR" ]; then
49
+    mkdir -p $DATADIR
50
+    chown $SYSTEM_USER $DATADIR
51
+fi
52
+
53
+start() {
54
+    echo -n "Starting $NAME: "
55
+    daemon --user $SYSTEM_USER "$DAEMON --config-file=$CONFIG_FILE &>/dev/null & echo \$! > $PIDFILE"
56
+    RETVAL=$?
57
+    echo
58
+    [ $RETVAL -eq 0 ] && touch $LOCKFILE
59
+    return $RETVAL
60
+}
61
+
62
+stop() {
63
+    echo -n "Stopping $NAME: "
64
+    #killproc $DAEMON -TERM
65
+    killproc -p $PIDFILE $DAEMON
66
+    RETVAL=$?
67
+    echo
68
+    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
69
+    return $RETVAL
70
+}
71
+
72
+restart() {
73
+    stop
74
+    start
75
+}
76
+
77
+rh_status() {
78
+    # run checks to determine if the service is running or use generic status
79
+    status $DAEMON
80
+}
81
+
82
+
83
+case "$1" in
84
+    start)
85
+        start
86
+        ;;
87
+
88
+    stop)
89
+        stop
90
+        ;;
91
+
92
+    restart)
93
+        restart
94
+        ;;
95
+
96
+    status)
97
+        rh_status
98
+        ;;
99
+    *)
100
+        echo $"Usage: $0 {start|stop|status|restart}"
101
+        exit 2
102
+esac
103
+exit $?

+ 45
- 25
python-agent/muranoagent/app.py View File

@@ -32,6 +32,7 @@ import types
32 32
 log = logging.getLogger(__name__)
33 33
 format_version = '2.0.0'
34 34
 
35
+
35 36
 class MuranoAgent(service.Service):
36 37
     def __init__(self):
37 38
         self._queue = ExecutionPlanQueue()
@@ -42,8 +43,8 @@ class MuranoAgent(service.Service):
42 43
         try:
43 44
             log.debug('Loading plugin %s', name)
44 45
             __import__(name)
45
-        except Exception, ex:
46
-            log.warn('Cannot load package %s', name, exc_info=1)
46
+        except Exception:
47
+            log.warn('Cannot load package %s', name, exc_info=True)
47 48
             pass
48 49
 
49 50
     def _load(self):
@@ -56,14 +57,15 @@ class MuranoAgent(service.Service):
56 57
 
57 58
     def start(self):
58 59
         self._load()
60
+        msg_iterator = self._wait_plan()
59 61
         while True:
60 62
             try:
61
-                self._loop_func()
63
+                self._loop_func(msg_iterator)
62 64
             except Exception as ex:
63 65
                 log.exception(ex)
64 66
                 sleep(5)
65 67
 
66
-    def _loop_func(self):
68
+    def _loop_func(self, msg_iterator):
67 69
         result, timestamp = self._queue.get_execution_plan_result()
68 70
         if result is not None:
69 71
             if self._send_result(result):
@@ -75,7 +77,7 @@ class MuranoAgent(service.Service):
75 77
             self._run(plan)
76 78
             return
77 79
 
78
-        self._wait_plan()
80
+        msg_iterator.next()
79 81
 
80 82
     def _run(self, plan):
81 83
         with ExecutionPlanRunner(plan) as runner:
@@ -111,26 +113,44 @@ class MuranoAgent(service.Service):
111 113
         return MqClient(**connection_params)
112 114
 
113 115
     def _wait_plan(self):
114
-        with self._create_rmq_client() as mq:
115
-            with mq.open(CONF.rabbitmq.input_queue,
116
-                         prefetch_count=1) as subscription:
117
-                msg = subscription.get_message(timeout=5)
118
-                if msg is not None and isinstance(msg.body, dict):
119
-                    if 'ID' not in msg.body and msg.id:
120
-                        msg.body['ID'] = msg.id
121
-                    err = self._verify_plan(msg.body)
122
-                    if err is None:
123
-                        self._queue.put_execution_plan(msg.body)
124
-                    else:
125
-                        try:
126
-                            execution_result = ExecutionResult.from_error(
127
-                                err, Bunch(msg.body))
128
-                            self._send_result(execution_result)
129
-                        except ValueError:
130
-                            log.warn('Execution result is not produced')
131
-
132
-                if msg is not None:
133
-                    msg.ack()
116
+        delay = 5
117
+        while True:
118
+            try:
119
+                with self._create_rmq_client() as mq:
120
+                    with mq.open(CONF.rabbitmq.input_queue,
121
+                                 prefetch_count=1) as subscription:
122
+                        while True:
123
+                            msg = subscription.get_message(timeout=5)
124
+                            if msg is not None and isinstance(msg.body, dict):
125
+                                self._handle_message(msg)
126
+
127
+                            if msg is not None:
128
+                                msg.ack()
129
+                                yield
130
+                            delay = 5
131
+            except KeyboardInterrupt:
132
+                break
133
+            except Exception:
134
+                log.warn('Communication error', exc_info=True)
135
+                sleep(delay)
136
+                delay = min(delay * 1.2, 60)
137
+
138
+    def _handle_message(self, msg):
139
+        print msg.body
140
+        if 'ID' not in msg.body and msg.id:
141
+            msg.body['ID'] = msg.id
142
+        err = self._verify_plan(msg.body)
143
+        if err is None:
144
+            self._queue.put_execution_plan(msg.body)
145
+        else:
146
+            try:
147
+                execution_result = ExecutionResult.from_error(
148
+                    err, Bunch(msg.body))
149
+
150
+                self._send_result(execution_result)
151
+            except ValueError:
152
+                log.warn('Execution result is not produced')
153
+
134 154
 
135 155
     def _verify_plan(self, plan):
136 156
         plan_format_version = plan.get('FormatVersion', '1.0.0')

+ 0
- 3
python-agent/muranoagent/config.py View File

@@ -110,6 +110,3 @@ def setup_logging():
110 110
 
111 111
     handler.setFormatter(formatter)
112 112
     root_logger.addHandler(handler)
113
-
114
-
115
-

+ 1
- 1
python-agent/muranoagent/exceptions.py View File

@@ -13,6 +13,7 @@
13 13
 # See the License for the specific language governing permissions and
14 14
 # limitations under the License.
15 15
 
16
+
16 17
 class AgentException(Exception):
17 18
     def __init__(self, code, message=None, additional_data=None):
18 19
         self._error_code = code
@@ -32,4 +33,3 @@ class CustomException(AgentException):
32 33
     def __init__(self, code, message=None, additional_data=None):
33 34
         super(CustomException, self).__init__(
34 35
             code + 100, message, additional_data)
35
-

+ 0
- 2
python-agent/muranoagent/execution_plan_queue.py View File

@@ -82,5 +82,3 @@ class ExecutionPlanQueue(object):
82 82
     def get_execution_plan_result(self):
83 83
         return self._get_first_file(
84 84
             ExecutionPlanQueue.result_filename)
85
-
86
-

+ 1
- 2
python-agent/muranoagent/executors/application/__init__.py View File

@@ -67,7 +67,6 @@ class ApplicationExecutor(object):
67 67
             raise muranoagent.exceptions.CustomException(
68 68
                 0,
69 69
                 message='Script {0} returned error code'.format(self._name),
70
-                additional_data= result)
70
+                additional_data=result)
71 71
 
72 72
         return Bunch(result)
73
-

+ 1
- 1
python-agent/muranoagent/files_manager.py View File

@@ -40,7 +40,7 @@ class FilesManager(object):
40 40
         filedef = self._files[file_id]
41 41
         filename = filedef['Name']
42 42
 
43
-        file_folder = os.path.join(script_folder,  os.path.dirname(filename))
43
+        file_folder = os.path.join(script_folder, os.path.dirname(filename))
44 44
         if not os.path.exists(file_folder):
45 45
             os.makedirs(file_folder)
46 46
 

+ 1
- 2
python-agent/muranoagent/openstack/common/eventlet_backdoor.py View File

@@ -104,8 +104,7 @@ def _listen(host, start_port, end_port, listen_func):
104 104
         try:
105 105
             return listen_func((host, try_port))
106 106
         except socket.error as exc:
107
-            if (exc.errno != errno.EADDRINUSE or
108
-               try_port >= end_port):
107
+            if (exc.errno != errno.EADDRINUSE or try_port >= end_port):
109 108
                 raise
110 109
             try_port += 1
111 110
 

+ 13
- 0
python-agent/muranoagent/tests/__init__.py View File

@@ -0,0 +1,13 @@
1
+#    Copyright (c) 2013 Mirantis, Inc.
2
+#
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.

+ 3
- 2
python-agent/requirements.txt View File

@@ -2,5 +2,6 @@ pbr>=0.5.21,<1.0
2 2
 semver
3 3
 bunch
4 4
 oslo.config>=1.2.0
5
-murano-common
6
-
5
+http://tarballs.openstack.org/murano-common/murano-common-release-0.3.tar.gz#egg=murano-common-release-0.3
6
+iso8601
7
+babel

+ 210
- 0
python-agent/setup-centos.sh View File

@@ -0,0 +1,210 @@
1
+#!/bin/sh
2
+#    Copyright (c) 2013 Mirantis, Inc.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+#
16
+#   CentOS script
17
+LOGLVL=1
18
+SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
19
+PREREQ_PKGS="git wget make gcc python-pip python-iso8601 python-six python-anyjson python-eventlet python-devel python-setuptools"
20
+PIPAPPS="pip python-pip pip-python"
21
+PIPCMD=""
22
+SERVICE_SRV_NAME="murano-agent"
23
+ETC_CFG_DIR="/etc/murano"
24
+
25
+
26
+
27
+# Functions
28
+# Loger function
29
+log()
30
+{
31
+	MSG=$1
32
+	if [ $LOGLVL -gt 0 ]; then
33
+		echo "LOG:> $MSG"
34
+	fi
35
+}
36
+
37
+# find pip
38
+find_pip()
39
+{
40
+	for cmd in $PIPAPPS
41
+	do
42
+		_cmd=$(which $cmd 2>/dev/null)
43
+		if [ $? -eq 0 ];then
44
+			break
45
+		fi
46
+	done
47
+	if [ -z $_cmd ];then
48
+		echo "Can't find \"pip\" in system, please install it first, exiting!"
49
+		exit 1
50
+	else
51
+		PIPCMD=$_cmd
52
+	fi
53
+}
54
+
55
+# Check or install package
56
+in_sys_pkg()
57
+{
58
+	PKG=$1
59
+	rpm -q $PKG > /dev/null 2>&1
60
+	if [ $? -eq 0 ]; then
61
+	    log "Package \"$PKG\" already installed"
62
+	else
63
+		log "Installing \"$PKG\"..."
64
+		yum install $PKG --assumeyes > /dev/null 2>&1
65
+		if [ $? -ne 0 ];then
66
+		    log "installation fails, exiting!!!"
67
+		    exit
68
+		fi
69
+	fi
70
+}
71
+
72
+# install
73
+inst()
74
+{
75
+# Checking packages
76
+	for PKG in $PREREQ_PKGS
77
+	do
78
+		in_sys_pkg $PKG
79
+	done
80
+# Find python pip
81
+	find_pip
82
+	MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
83
+	if [ -e $MRN_CND_SPY ]; then
84
+		chmod +x $MRN_CND_SPY
85
+		log "$MRN_CND_SPY output:_____________________________________________________________"
86
+## Setup through pip
87
+		# Creating tarball
88
+		rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
89
+		cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
90
+		if [ $? -ne 0 ];then
91
+			log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
92
+			exit 1
93
+		fi
94
+		rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
95
+		cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist
96
+		if [ $? -ne 0 ];then
97
+			log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
98
+			exit 1
99
+		fi
100
+		# Running tarball install
101
+		TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/murano-agent*.tar.gz`)
102
+		$PIPCMD install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
103
+		if [ $? -ne 0 ];then
104
+			log "$PIPCMD install \"$TRBL_FILE\" FAILS, recreate terball with \"python setup.py sdist\" command, exiting!!!"
105
+			exit 1
106
+		fi
107
+		# Creating etc directory for config files
108
+		if [ ! -d $ETC_CFG_DIR ];then
109
+			log "Creating $ETC_CFG_DIR direcory..."
110
+			mkdir -p $ETC_CFG_DIR
111
+			if [ $? -ne 0 ];then
112
+				log "Can't create $ETC_CFG_DIR, exiting!!!"
113
+				exit 1
114
+			fi
115
+		fi
116
+		log "Making sample configuration file at \"$ETC_CFG_DIR\""
117
+		cp -f "$SERVICE_CONTENT_DIRECTORY/etc/agent.conf" "$ETC_CFG_DIR/agent.conf"
118
+	else
119
+		log "$MRN_CND_SPY not found!"
120
+	fi
121
+}
122
+
123
+# searching for service executable in path
124
+get_service_exec_path()
125
+{
126
+	if [ -z "$SERVICE_EXEC_PATH" ]; then
127
+		SERVICE_EXEC_PATH=$(which muranoagent)
128
+		if [ $? -ne 0 ]; then
129
+			log "Can't find \"muranoagent ($SERVICE_SRV_NAME)\", please install the \"$SERVICE_SRV_NAME\" by running \"$(basename "$0") install\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
130
+			exit 1
131
+		fi
132
+	else
133
+		if [ ! -x "$SERVICE_EXEC_PATH" ]; then
134
+			log "\"$SERVICE_EXEC_PATH\" in not executable, please install the muranoagent \"($SERVICE_SRV_NAME)\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
135
+			exit 1
136
+		fi
137
+	fi
138
+}
139
+
140
+# uninstall
141
+uninst()
142
+{
143
+	# Uninstall trough  pip
144
+	find_pip
145
+	# looking up for python package installed
146
+	PYPKG=$SERVICE_SRV_NAME
147
+	_pkg=$($PIPCMD freeze | grep $PYPKG)
148
+	if [ $? -eq 0 ]; then
149
+		log "Removing package \"$PYPKG\" with pip"
150
+		$PIPCMD uninstall $_pkg --yes
151
+	else
152
+		log "Python package \"$PYPKG\" not found"
153
+	fi
154
+}
155
+
156
+# inject init
157
+injectinit()
158
+{
159
+	log "Enabling $SERVICE_SRV_NAME in init.d..."
160
+	cp -f "$SERVICE_CONTENT_DIRECTORY/init.d/murano-agent-el6" "/etc/init.d/$SERVICE_SRV_NAME"
161
+	sed -i "s/DAEMON=.*/DAEMON=$(echo $SERVICE_EXEC_PATH | sed -e 's/\//\\\//g')/" /etc/init.d/$SERVICE_SRV_NAME
162
+	chmod 755 /etc/init.d/$SERVICE_SRV_NAME
163
+	chkconfig --add $SERVICE_SRV_NAME
164
+	chkconfig $SERVICE_SRV_NAME on
165
+}
166
+
167
+purgeinit()
168
+{
169
+	log "Removing from init.d..."
170
+	chkconfig $SERVICE_SRV_NAME off
171
+	chkconfig --del $SERVICE_SRV_NAME
172
+	rm -f /etc/init.d/$SERVICE_SRV_NAME
173
+	#Fedora compat.
174
+	systemctl --system daemon-reload > /dev/null 2>&1
175
+}
176
+
177
+# Command line args'
178
+COMMAND="$1"
179
+case $COMMAND in
180
+	inject-init )
181
+		get_service_exec_path
182
+		log "Injecting \"$SERVICE_SRV_NAME\" to init..."
183
+		injectinit
184
+		postinst
185
+		;;
186
+
187
+	install )
188
+		inst
189
+		get_service_exec_path
190
+		injectinit
191
+		;;
192
+
193
+	purge-init )
194
+		log "Purging \"$SERVICE_SRV_NAME\" from init..."
195
+		service $SERVICE_SRV_NAME stop
196
+		purgeinit
197
+		;;
198
+
199
+	uninstall )
200
+		log "Uninstalling \"$SERVICE_SRV_NAME\" from system..."
201
+		service $SERVICE_SRV_NAME stop
202
+		purgeinit
203
+		uninst
204
+		;;
205
+
206
+	* )
207
+		echo -e "Usage: $(basename "$0") command \nCommands:\n\tinstall - Install $SERVICE_SRV_NAME software\n\tuninstall - Uninstall $SERVICE_SRV_NAME software\n\tinject-init - Add $SERVICE_SRV_NAME to the system start-up\n\tpurge-init - Remove $SERVICE_SRV_NAME from the system start-up"
208
+		exit 1
209
+		;;
210
+esac

+ 1
- 2
python-agent/setup.cfg View File

@@ -1,8 +1,7 @@
1 1
 [metadata]
2 2
 name = murano-agent
3
+version = 0.3
3 4
 summary = Python Murano Agent
4
-description-file =
5
-    README.rst
6 5
 license = Apache License, Version 2.0
7 6
 author = Mirantis, Inc.
8 7
 author-email = murano-all@lists.openstack.org

+ 0
- 0
python-agent/setup.py View File


+ 206
- 0
python-agent/setup.sh View File

@@ -0,0 +1,206 @@
1
+#!/bin/sh
2
+#    Copyright (c) 2013 Mirantis, Inc.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+#
16
+#   Ubuntu script
17
+LOGLVL=1
18
+SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
19
+PREREQ_PKGS="git wget make gcc python-pip python-iso8601 python-six python-anyjson python-eventlet python-dev python-setuptools"
20
+PIPAPPS="pip python-pip pip-python"
21
+PIPCMD=""
22
+SERVICE_SRV_NAME="murano-agent"
23
+ETC_CFG_DIR="/etc/murano"
24
+
25
+
26
+
27
+# Functions
28
+# Loger function
29
+log()
30
+{
31
+	MSG=$1
32
+	if [ $LOGLVL -gt 0 ]; then
33
+		echo "LOG:> $MSG"
34
+	fi
35
+}
36
+
37
+# find pip
38
+find_pip()
39
+{
40
+	for cmd in $PIPAPPS
41
+	do
42
+		_cmd=$(which $cmd 2>/dev/null)
43
+		if [ $? -eq 0 ];then
44
+			break
45
+		fi
46
+	done
47
+	if [ -z $_cmd ];then
48
+		echo "Can't find \"pip\" in system, please install it first, exiting!"
49
+		exit 1
50
+	else
51
+		PIPCMD=$_cmd
52
+	fi
53
+}
54
+
55
+# Check or install package
56
+in_sys_pkg()
57
+{
58
+	PKG=$1
59
+	dpkg -s $PKG > /dev/null 2>&1
60
+	if [ $? -eq 0 ]; then
61
+		log "Package \"$PKG\" already installed"
62
+	else
63
+		log "Installing \"$PKG\"..."
64
+		apt-get install $PKG --yes > /dev/null 2>&1
65
+		if [ $? -ne 0 ];then
66
+			log "installation fails, exiting!!!"
67
+			exit
68
+		fi
69
+	fi
70
+}
71
+
72
+# install
73
+inst()
74
+{
75
+# Checking packages
76
+	for PKG in $PREREQ_PKGS
77
+	do
78
+		in_sys_pkg $PKG
79
+	done
80
+# Find python pip
81
+	find_pip
82
+	MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
83
+	if [ -e $MRN_CND_SPY ]; then
84
+		chmod +x $MRN_CND_SPY
85
+		log "$MRN_CND_SPY output:_____________________________________________________________"
86
+## Setup through pip
87
+		# Creating tarball
88
+		rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
89
+		cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
90
+		if [ $? -ne 0 ];then
91
+			log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
92
+			exit 1
93
+		fi
94
+		rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
95
+		cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist
96
+		if [ $? -ne 0 ];then
97
+			log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
98
+			exit 1
99
+		fi
100
+		# Running tarball install
101
+		TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/murano-agent*.tar.gz`)
102
+		$PIPCMD install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
103
+		if [ $? -ne 0 ];then
104
+			log "$PIPCMD install \"$TRBL_FILE\" FAILS, recreate terball with \"python setup.py sdist\" command, exiting!!!"
105
+			exit 1
106
+		fi
107
+		# Creating etc directory for config files
108
+		if [ ! -d $ETC_CFG_DIR ];then
109
+			log "Creating $ETC_CFG_DIR direcory..."
110
+			mkdir -p $ETC_CFG_DIR
111
+			if [ $? -ne 0 ];then
112
+				log "Can't create $ETC_CFG_DIR, exiting!!!"
113
+				exit 1
114
+			fi
115
+		fi
116
+		log "Making sample configuration file at \"$ETC_CFG_DIR\""
117
+		cp -f "$SERVICE_CONTENT_DIRECTORY/etc/agent.conf" "$ETC_CFG_DIR/agent.conf"
118
+	else
119
+		log "$MRN_CND_SPY not found!"
120
+	fi
121
+}
122
+
123
+# searching for service executable in path
124
+get_service_exec_path()
125
+{
126
+	if [ -z "$SERVICE_EXEC_PATH" ]; then
127
+		SERVICE_EXEC_PATH=$(which muranoagent)
128
+		if [ $? -ne 0 ]; then
129
+			log "Can't find \"muranoagent ($SERVICE_SRV_NAME)\", please install the \"$SERVICE_SRV_NAME\" by running \"$(basename "$0") install\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
130
+			exit 1
131
+		fi
132
+	else
133
+		if [ ! -x "$SERVICE_EXEC_PATH" ]; then
134
+			log "\"$SERVICE_EXEC_PATH\" in not executable, please install the muranoagent \"($SERVICE_SRV_NAME)\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
135
+			exit 1
136
+		fi
137
+	fi
138
+}
139
+
140
+# uninstall
141
+uninst()
142
+{
143
+	# Uninstall trough  pip
144
+	find_pip
145
+	# looking up for python package installed
146
+	PYPKG=$SERVICE_SRV_NAME
147
+	_pkg=$($PIPCMD freeze | grep $PYPKG)
148
+	if [ $? -eq 0 ]; then
149
+		log "Removing package \"$PYPKG\" with pip"
150
+		$PIPCMD uninstall $_pkg --yes
151
+	else
152
+		log "Python package \"$PYPKG\" not found"
153
+	fi
154
+}
155
+
156
+# inject init
157
+injectinit()
158
+{
159
+	log "Enabling $SERVICE_SRV_NAME in init.d..."
160
+	cp -f "$SERVICE_CONTENT_DIRECTORY/init.d/murano-agent-deb" "/etc/init.d/$SERVICE_SRV_NAME"
161
+	sed -i "s/DAEMON=.*/DAEMON=$(echo $SERVICE_EXEC_PATH | sed -e 's/\//\\\//g')/" /etc/init.d/$SERVICE_SRV_NAME
162
+	chmod 755 /etc/init.d/$SERVICE_SRV_NAME
163
+	update-rc.d $SERVICE_SRV_NAME defaults
164
+}
165
+
166
+purgeinit()
167
+{
168
+	log "Removing from init.d..."
169
+	update-rc.d -f $SERVICE_SRV_NAME remove
170
+	rm -f /etc/init.d/$SERVICE_SRV_NAME
171
+}
172
+
173
+# Command line args'
174
+COMMAND="$1"
175
+case $COMMAND in
176
+	inject-init )
177
+		get_service_exec_path
178
+		log "Injecting \"$SERVICE_SRV_NAME\" to init..."
179
+		injectinit
180
+		postinst
181
+		;;
182
+
183
+	install )
184
+		inst
185
+		get_service_exec_path
186
+		injectinit
187
+		;;
188
+
189
+	purge-init )
190
+		log "Purging \"$SERVICE_SRV_NAME\" from init..."
191
+		service $SERVICE_SRV_NAME stop
192
+		purgeinit
193
+		;;
194
+
195
+	uninstall )
196
+		log "Uninstalling \"$SERVICE_SRV_NAME\" from system..."
197
+		service $SERVICE_SRV_NAME stop
198
+		purgeinit
199
+		uninst
200
+		;;
201
+
202
+	* )
203
+		echo -e "Usage: $(basename "$0") command \nCommands:\n\tinstall - Install $SERVICE_SRV_NAME software\n\tuninstall - Uninstall $SERVICE_SRV_NAME software\n\tinject-init - Add $SERVICE_SRV_NAME to the system start-up\n\tpurge-init - Remove $SERVICE_SRV_NAME from the system start-up"
204
+		exit 1
205
+		;;
206
+esac

+ 18
- 0
python-agent/test-requirements.txt View File

@@ -0,0 +1,18 @@
1
+# Needed for testing
2
+unittest2
3
+coverage>=3.6
4
+fixtures>=0.3.14
5
+mox>=0.5.3
6
+nose
7
+nose-exclude
8
+openstack.nose_plugin>=0.7
9
+nosehtmloutput>=0.0.3
10
+pep8==1.3.3
11
+sphinx>=1.1.2
12
+requests>=1.1
13
+testtools>=0.9.32
14
+mock>=1.0
15
+
16
+# Optional packages that should be installed when testing
17
+xattr>=0.4
18
+pysendfile==2.0.0

Loading…
Cancel
Save