cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
sample_test.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 from datetime import datetime
21 import hashlib
22 
23 actions = []
24 
25 now = str(datetime.now())
26 
27 u_admin = {'l': 'cc1', 'p': 'cc1', 'cm': 0}
28 u_fake = {'l': 'cc1', 'p': 'xxx', 'cm': 0}
29 
30 # Action type is defined by 'type' key.
31 
32 # Action syntax for functions ('type' == 'function' or without 'type'):
33 #
34 # u or user - (optional) dictionary with user information: l(login), p(password) and cm(cm id)
35 # fname - (required) function name
36 # args - (required) function arguments list
37 # estatus - (optional) excepted function status (cannot be exception). If not given,
38 # excepted status is 'ok'
39 # store_as - (optional) store result in dictionary under given name
40 #
41 # Parameters starting with @ are substituted to stored values. E.g.:
42 # - Call vm list function with store_as='vm_list'. The result's data will be stored
43 # under vm_list name
44 # - Parameter @r["vm_list"][1]['id'] will be substituted to id of first virtual
45 # machine's id stored in stored_objects. Use only single (') quotation marks
46 
47 # Action syntax for execs ('type' == 'exec'):
48 #
49 # command - (required) command to execute
50 # estatus - (optional) expected return code. Default is 0
51 
52 # Get message list
53 actions.append({'u': u_admin, 'fname': 'message.user.list', 'args': []})
54 
55 # Store image lists
56 actions.append({'u': u_admin, 'fname': 'image.user.list', 'args': [{'access': 0, 'type': 2}], 'store_as': 'user_images', 'estatus': 'ok'})
57 actions.append({'u': u_admin, 'fname': 'image.user.list', 'args': [{'access': 1, 'type': 2}], 'store_as': 'public_images', 'estatus': 'ok'})
58 actions.append({'u': u_admin, 'fname': 'image.user.list', 'args': [{'access': 2, 'type': 2}], 'store_as': 'group_images', 'estatus': 'ok'})
59 
60 # Sleep for 10 seconds
61 actions.append({'type': 'sleep', 'time': 10})
62 
63 # Execute apt-get
64 actions.append({'type': 'exec', 'command': 'apt-get',
65  'args': ['install', 'python-mysql']})
66 
67 # Execute ssh to remote server with command. Wait for command stdout is exactly 5.
68 # Reply this tet for 6 minutes (360 seconds)
69 actions.append({'type': 'exec', 'command': 'ssh',
70  'args': ['root@example.net', '"w | wc -l"'],
71  'wait_resonse': 'stdout == "5"',
72  'wait_max': 360})
73