cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
instance_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 ##
21 # @package src.ec2.instance_test
22 #
23 # @copyright Copyright (c) 2012 Institute of Nuclear Physics PAS <http://www.ifj.edu.pl/>
24 # @author Oleksandr Gituliar <gituliar@gmail.com>
25 #
26 
27 from xmlrpclib import DateTime
28 
29 from ec2.base.action import Action
30 from ec2.base.test import TestCase
31 
32 
33 class InstanceTestCase(TestCase):
34 
36  self.cluster_manager.vm.user.list.return_value = [{
37  'id': '1234',
38  'priv_ip': '5.6.7.8',
39  'pub_ip': '1.2.3.4',
40  'state': 1,
41  'user_id': '5678',
42  }]
43  self.cluster_manager.vm.user.get_by_id.return_value = {
44  'id': '1234',
45  'image_name': 'test image',
46  'priv_ip': '5.6.7.8',
47  'pub_ip': '1.2.3.4',
48  'state': 1,
49  'start_time': DateTime('20121015T16:10:00'),
50  'user_id': '5678',
51  }
52 
53  response = Action({
54  'Action': 'DescribeInstances',
55  }, self.cluster_manager).execute()
56  self.assertMultiLineEqual(
57  response,
58  """<?xml version="1.0" encoding="UTF-8"?>
59  <DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-06-01/">
60  <requestId>00000000-0000-0000-0000-000000000000</requestId>
61  <reservationSet>
62  <item>
63  <reservationId>r-00000000</reservationId>
64  <ownerId>5678</ownerId>
65  <instancesSet>
66  <item>
67  <hypervisor>kvm</hypervisor>
68  <imageId>test image</imageId>
69  <instanceId>1234</instanceId>
70  <instanceState>
71  <code>16</code>
72  <name>running</name>
73  </instanceState>
74  <instanceType>m1.small</instanceType>
75  <ipAddress>1.2.3.4</ipAddress>
76  <launchTime>2012-10-15T16:10:00</launchTime>
77  <placement>
78  <availabilityZone>test_cm</availabilityZone>
79  </placement>
80  <privateIpAddress>5.6.7.8</privateIpAddress>
81  <reason></reason>
82  </item>
83  </instancesSet>
84  </item>
85  </reservationSet>
86  </DescribeInstancesResponse>
87  """
88  )
89 
91  self.cluster_manager.vm.user.destroy.return_value = None
92 
93  response = Action({
94  'Action': 'TerminateInstances',
95  'InstanceId.1': '1',
96  }, self.cluster_manager).execute()
97 
98  self.assertMultiLineEqual(
99  response,
100  """<?xml version="1.0" encoding="UTF-8"?>
101  <TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-06-01/">
102  <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
103  <instancesSet>
104  <item>
105  <instanceId>1</instanceId>
106  <currentState>
107  <code>32</code>
108  <name>shutting-down</name>
109  </currentState>
110  <previousState>
111  <code>16</code>
112  <name>running</name>
113  </previousState>
114  </item>
115  </instancesSet>
116  </TerminateInstancesResponse>
117  """
118  )
119