1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Marga Millet < millet@cisco.com>'
import sys
import os
import yaml
import time
# import iptools
import amulet
import unittest
import paramiko
from collections import OrderedDict
"""
IMPORTANT: Make sure you execute this script in an environment with
at least two physical nodes (non virtual machines) and using the tag
called "physical".
"""
VSM_AMULET_FILE = os.environ.get("VSM_AMULET_FILE", None)
if not VSM_AMULET_FILE:
raise Exception("Please define VSM_AMULET_FILE environment variable "
"with path to the amulet.yaml file config for amulet.")
"""
This need a yaml file with the configuration for the amulet testing.
Similar to config.yaml of the VSM charm.
Example:
export VSM_AMULET_FILE = "~/amulet.yaml"
and the amulet.yaml contains:
vsm-pri:
n1kv-source: ppa:cisco-n1kv/n1kv-updates
n1kv-vsm-domain-id: 10
n1kv-vsm-password: "mypassw0rd"
n1kv-vsm-mgmt-ip: "10.10.10.10"
n1kv-vsm-mgmt-netmask: "255.255.255.0"
n1kv-vsm-mgmt-gateway: 10.10.10.1"
n1kv-phy-intf-bridge: "eth0"
"""
try:
f = open(VSM_AMULET_FILE, 'r')
except IOError:
msg = 'Error: Cannot open %s.' % VSM_AMULET_FILE
amulet.raise_status(amulet.FAIL, msg=msg)
else:
config = yaml.load(f)
n1kv_source = config["vsm-pri"]["n1kv-source"]
vsm_admin_pwd = config["vsm-pri"]["n1kv-vsm-password"]
vsm_domain_id = config["vsm-pri"]["n1kv-vsm-domain-id"]
vsm_mgmt_ip = config["vsm-pri"]["n1kv-vsm-mgmt-ip"]
vsm_mgmt_mask = config["vsm-pri"]["n1kv-vsm-mgmt-netmask"]
vsm_gateway = config["vsm-pri"]["n1kv-vsm-mgmt-gateway"]
vsm_phy_intf = config["vsm-pri"]["n1kv-phy-intf-bridge"]
f.close()
# if (not n1kv_source) or (not vsm_admin_pwd):# or
# (not is_number(vsm_domain_id)) or (vsm_domain_id <= 0) or
# iptools.ipv4.validate_ip(vsm_mgmt_ip) or
# iptools.ipv4.validate_netmask(vsm_mgmt_mask) or
# iptools.ipv4.validate_ip(vsm_gateway):
# amulet.raise_status(amulet.FAIL, "Error: Check config parameters")
class VSMTest(unittest.TestCase):
def setUp(self):
pass
def test_deployment_primary_vsm(self):
"""Test the deployment of the VSM VM"""
self.deployment = amulet.Deployment(series="trusty", sentries=False)
self.deployment.add("vsm-pri", charm="vsm",
constraints=OrderedDict([("tags", "physical")]))
self.deployment.configure("vsm-pri", {
'n1kv-source': n1kv_source,
'n1kv-vsm-domain-id': vsm_domain_id,
'n1kv-vsm-password': vsm_admin_pwd,
'n1kv-vsm-mgmt-ip': vsm_mgmt_ip,
'n1kv-vsm-mgmt-netmask': vsm_mgmt_mask,
'n1kv-vsm-mgmt-gateway': vsm_gateway,
'n1kv-phy-intf-bridge': vsm_phy_intf,
})
seconds = 800
try:
self.deployment.setup(timeout=seconds)
except amulet.helpers.TimeoutError:
msg = 'The environment did not setup in %d seconds.' % seconds
amulet.raise_status(amulet.SKIP, msg=msg)
except:
raise
# Wait for VSM to come up
time.sleep(180)
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(vsm_mgmt_ip, username="admin", password=vsm_admin_pwd,
timeout=120)
except Exception as e:
err = 'Error(%s): Unable to ssh to VSM VM (%s)' % (e, vsm_mgmt_ip)
amulet.raise_status(amulet.SKIP, msg=err)
stdin, stdout, stderr = ssh.exec_command("show module")
msg = stdout.readlines()
if str(msg).find('active *') == -1:
err = 'Error: VSM is not Active (%s)' % (msg)
amulet.raise_status(amulet.SKIP, msg=err)
ssh.close()
def test_deployment_standby_vsm(self):
"""Test the deployment of a secondary VSM VM.
This test cases assumes that test_deployment_primary_vsm has been
executed first. Hence the primary VSM VM is running.
"""
self.deployment = amulet.Deployment(series="trusty", sentries=False)
self.deployment.add("vsm-sec", charm="vsm",
constraints=OrderedDict([("tags", "physical")]))
self.deployment.configure("vsm-sec", {
'n1kv-source': n1kv_source,
'n1kv-vsm-domain-id': vsm_domain_id,
'n1kv-vsm-name': 'vsm-s',
'n1kv-vsm-role': 'secondary',
'n1kv-vsm-password': vsm_admin_pwd,
'n1kv-phy-intf-bridge': vsm_phy_intf,
})
seconds = 800
try:
self.deployment.setup(timeout=seconds)
except amulet.helpers.TimeoutError:
msg = 'The environment did not setup in %d seconds.' % seconds
amulet.raise_status(amulet.SKIP, msg=msg)
except:
raise
# Wait for VSM to come up and connect with the primary
time.sleep(300)
# Connect to the primary VSM and verify that it has conectivity
# with the secondary
paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(vsm_mgmt_ip, username="admin", password=vsm_admin_pwd)
except Exception as e:
err = 'Error(%s): No ssh to primary VSM VM (%s)' % (e, vsm_mgmt_ip)
amulet.raise_status(amulet.SKIP, msg=err)
stdin, stdout, stderr = ssh.exec_command("show module")
msg = stdout.readlines()
if str(msg).find('ha-standby') == -1:
err = 'Error: VSM is not Standby VM (%s)' % (msg)
amulet.raise_status(amulet.SKIP, msg=err)
ssh.close()
if __name__ == "__main__":
unittest.main()
|