Merge lp:~bladernr/checkbox/remove-ftp-network-test into lp:checkbox

Proposed by Jeff Lane 
Status: Merged
Approved by: Zygmunt Krynicki
Approved revision: 3815
Merged at revision: 3817
Proposed branch: lp:~bladernr/checkbox/remove-ftp-network-test
Merge into: lp:checkbox
Diff against target: 309 lines (+8/-204)
1 file modified
providers/plainbox-provider-checkbox/bin/network (+8/-204)
To merge this branch: bzr merge lp:~bladernr/checkbox/remove-ftp-network-test
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+260317@code.launchpad.net

Description of the change

Removes FTP bits from p-p-c/bin/network that are no longer needed and have been removed from all test cases.

Rebased prior to this MR on the current trunk for Checkbox.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'providers/plainbox-provider-checkbox/bin/network'
2--- providers/plainbox-provider-checkbox/bin/network 2015-05-01 13:08:09 +0000
3+++ providers/plainbox-provider-checkbox/bin/network 2015-05-27 14:42:26 +0000
4@@ -1,10 +1,11 @@
5 #!/usr/bin/env python3
6 """
7-Copyright (C) 2012-2014 Canonical Ltd.
8+Copyright (C) 2012-2015 Canonical Ltd.
9
10 Authors
11 Jeff Marcom <jeff.marcom@canonical.com>
12 Daniel Manrique <roadmr@ubuntu.com>
13+ Jeff Lane <jeff@ubuntu.com>
14
15 This program is free software: you can redistribute it and/or modify
16 it under the terms of the GNU General Public License version 3,
17@@ -24,8 +25,6 @@
18 RawTextHelpFormatter
19 )
20 import fcntl
21-import ftplib
22-from ftplib import FTP
23 import logging
24 import os
25 import re
26@@ -153,154 +152,6 @@
27 return 1
28
29
30-class FTPPerformanceTest(object):
31- """Provides file transfer rate based information while
32- using the FTP protocol and sending a file (DEFAULT=1GB)
33- over the local or public network using a specified network
34- interface on the host."""
35-
36- def __init__(
37- self,
38- target,
39- username,
40- password,
41- interface,
42- binary_size=1,
43- file2send="ftp_performance_test"):
44-
45- self.target = target
46- self.username = username
47- self.password = password
48- self.iface = Interface(interface)
49- self.binary_size = binary_size
50- self.file2send = file2send
51-
52- def _make_file2send(self):
53- """
54- Makes binary file to send over FTP.
55- Size defaults to 1GB if not supplied.
56- """
57-
58- logging.debug("Creating %sGB file", self.binary_size)
59-
60- file_size = (1024 * 1024 * 1024) * self.binary_size
61- with open(self.file2send, "wb") as out:
62- out.seek((file_size) - 1)
63- out.write('\0'.encode())
64-
65- def send_file(self, filename=None):
66- """
67- Sends file over the network using FTP and returns the
68- amount of bytes sent and delay between send and completed.
69- """
70-
71- if filename is None:
72- file = open(self.file2send, 'rb')
73- filename = self.file2send
74-
75- send_time = time.time()
76-
77- try:
78- logging.debug("Sending file")
79- self.remote.storbinary("STOR " + filename, file, 1024)
80- except (ftplib.all_errors) as send_failure:
81- logging.error("Failed to send file to %s", self.target)
82- logging.error("Reason: %s", send_failure)
83- return 0, 0
84-
85- file.close()
86-
87- time_lapse = time.time() - send_time
88- bytes_sent = os.stat(filename).st_size
89-
90- return bytes_sent, time_lapse
91-
92- def close_connection(self):
93- """
94- Close connection to remote FTP target
95- """
96- self.remote.close()
97-
98- def connect(self):
99- """
100- Connects to FTP target and set the current directory as /
101- """
102-
103- logging.debug("Connecting to %s", self.target)
104- try:
105- self.remote = FTP(self.target)
106- self.remote.set_debuglevel(2)
107- self.remote.set_pasv(True)
108- except socket.error as connect_exception:
109- logging.error("Failed to connect to: %s: %s", self.target,
110- connect_exception)
111- return False
112-
113- logging.debug("Logging in")
114- logging.debug("{USER:%s, PASS:%s}", self.username, self.password)
115-
116- try:
117- self.remote.login(self.username, self.password)
118- except ftplib.error_perm as login_exception:
119- logging.error("failed to log into target: %s: %s", self.target,
120- login_exception)
121- return False
122-
123- default_out_dir = ""
124- self.remote.cwd(default_out_dir)
125- return True
126-
127- def run(self):
128-
129- info = {
130- "Interface": self.iface.interface,
131- "HWAddress": self.iface.macaddress,
132- "Duplex": self.iface.duplex_mode,
133- "Speed": self.iface.max_speed,
134- "Status": self.iface.status
135- }
136-
137- logging.debug(info)
138-
139- if not os.path.isfile(self.file2send):
140- self._make_file2send()
141-
142- # Connect to FTP target and send file
143- connected = self.connect()
144-
145- if connected is False:
146- return 3
147-
148- datasize, delay = self.send_file()
149-
150- # Remove created binary
151- try:
152- os.remove(self.file2send)
153- except (IOError, OSError) as file_delete_error:
154- logging.error("Could not remove previous ftp file")
155- logging.error(file_delete_error)
156-
157- if connected and datasize > 0:
158-
159- logging.debug("Bytes sent (%s): %.2f seconds", datasize, delay)
160-
161- # Calculate transfer rate and determine pass/fail status
162- mbs_speed = float(datasize / 131072) / float(delay)
163- percent = (mbs_speed / int(info["Speed"])) * 100
164- print("Transfer speed:")
165- print("%3.2f%% of" % percent)
166- print("theoretical max %smbs" % int(info["Speed"]))
167-
168- if percent < 40:
169- logging.warn("Poor network performance detected")
170- return 30
171-
172- logging.debug("Passed benchmark")
173- else:
174- print("Failed sending file via ftp")
175- return 1
176-
177-
178 class StressPerformanceTest:
179
180 def __init__(self, interface, target):
181@@ -438,10 +289,7 @@
182 # - If command-line args were given, they take precedence
183 # - Next come environment variables, if set.
184
185- params = {"test_target_ftp": None,
186- "test_user": None,
187- "test_pass": None,
188- "test_target_iperf": None}
189+ params = {"test_target_iperf": None}
190
191 # See if we have environment variables
192 for key in params.keys():
193@@ -450,12 +298,7 @@
194 # Finally, see if we have the command-line arguments that are the ultimate
195 # override.
196 if args.target:
197- params["test_target_ftp"] = args.target
198 params["test_target_iperf"] = args.target
199- if args.username:
200- params["test_user"] = args.username
201- if args.password:
202- params["test_pass"] = args.password
203
204 return params
205
206@@ -489,13 +332,9 @@
207 # Get the actual test data from one of two possible sources
208 test_parameters = get_test_parameters(args, os.environ)
209
210- test_user = test_parameters["test_user"]
211- test_pass = test_parameters["test_pass"]
212 if (args.test_type.lower() == "iperf" or
213 args.test_type.lower() == "stress"):
214 test_target = test_parameters["test_target_iperf"]
215- else:
216- test_target = test_parameters["test_target_ftp"]
217
218 # Validate that we got reasonable values
219 if not test_target or "example.com" in test_target:
220@@ -509,16 +348,6 @@
221 logging.info("Please run this script with -h to see more details on how to configure")
222 sys.exit(1)
223
224- if args.test_type.lower() == 'ftp' and not (test_user and test_pass):
225- logging.error("Target user/password have not been supplied.")
226- logging.info("Target user/password can be configured 3 different ways:")
227- logging.info("1- If calling the script directly, give --user or --pass option")
228- logging.info("2- Define the TEST_USER or TEST_PASS environment variables")
229- logging.info("3- (If running the test via checkbox/plainbox, define the ")
230- logging.info("settings in /etc/xdg/canonical-certification.conf)")
231- logging.info("Please run this script with -h to see more details on how to configure")
232- sys.exit(1)
233-
234 # Testing begins here!
235 #
236 # Make sure that the interface is indeed connected
237@@ -558,16 +387,8 @@
238 logging.error("Can't ping test server on %s", args.interface)
239 return 1
240
241- # Execute FTP transfer benchmarking test
242- if args.test_type.lower() == "ftp":
243- ftp_benchmark = FTPPerformanceTest(
244- test_target, test_user, test_pass, args.interface)
245-
246- if args.datasize:
247- ftp_benchmark.binary_size = int(args.datasize)
248- result = ftp_benchmark.run()
249-
250- elif args.test_type.lower() == "iperf":
251+ # Execute requested networking test
252+ if args.test_type.lower() == "iperf":
253 iperf_benchmark = IPerfPerformanceTest(args.interface, test_target,
254 args.fail_threshold)
255 if args.datasize:
256@@ -629,11 +450,6 @@
257 Example NIC information usage:
258 network info -i eth0 --max-speed
259
260-For running ftp benchmark test:
261-network test -i eth0 -t ftp
262---target 192.168.0.1 --username USERID --password PASSW0RD
263---datasize-2
264-
265 For running iperf test:
266 network test -i eth0 -t iperf --target 192.168.0.1
267 NOTE: The iperf test requires an iperf server running on the same network
268@@ -655,17 +471,11 @@
269 Environment variables
270 =====================
271 The variables are:
272-TEST_TARGET_FTP
273-TEST_USER
274-TEST_PASS
275 TEST_TARGET_IPERF
276
277 example config file
278 ===================
279 [environment]
280-TEST_TARGET_FTP = ftp-server.example.com
281-TEST_USER = my-name
282-TEST_PASS = a-password
283 TEST_TARGET_IPERF = iperf-server.example.com
284
285
286@@ -688,20 +498,14 @@
287 '-i', '--interface', type=str, required=True)
288 test_parser.add_argument(
289 '-t', '--test_type', type=str,
290- choices=("ftp", "iperf", "stress"), default="ftp",
291- help=("[FTP *Default*]"))
292+ choices=("iperf", "stress"), default="iperf",
293+ help=("[iperf *Default*]"))
294 test_parser.add_argument('--target', type=str)
295 test_parser.add_argument(
296- '--username', type=str, help=("For FTP test only"))
297- test_parser.add_argument(
298- '--password', type=str, help=("For FTP test only"))
299- test_parser.add_argument(
300 '--datasize', type=str,
301 default="1",
302 help=("Amount of data to send. For iperf tests this will direct "
303- "iperf to send DATASIZE GB of data. For FTP tests, this "
304- "will create a file that is DATASIZE GB large to be transmitted "
305- "to the target."))
306+ "iperf to send DATASIZE GB of data to the target."))
307 test_parser.add_argument(
308 '--config', type=str,
309 default="/etc/checkbox.d/network.cfg",

Subscribers

People subscribed via source and target branches