From 620425f10d5ce8ed46b5e3a3b8b9bdcf67811c75 Mon Sep 17 00:00:00 2001 From: Anton Beloglazov Date: Thu, 26 Mar 2015 11:14:07 +1100 Subject: [PATCH] Added platform-dependent selection of the etherwake program name: ether-wake for RedHat and CentOS, etherwake for others --- neat/globals/manager.py | 10 +++++++++- tests/globals/test_manager.py | 26 +++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/neat/globals/manager.py b/neat/globals/manager.py index 5491794..d8fa9c9 100644 --- a/neat/globals/manager.py +++ b/neat/globals/manager.py @@ -84,6 +84,13 @@ from neat.db_utils import * import logging log = logging.getLogger(__name__) +import platform +dist = platform.linux_distribution(full_distribution_name=0)[0] +if dist in ['redhat', 'centos']: + etherwake = 'ether-wake' +else: + etherwake = 'etherwake' + ERRORS = { 400: 'Bad input parameter: incorrect or missing parameters', @@ -857,7 +864,8 @@ def switch_hosts_on(db, ether_wake_interface, host_macs, hosts): for host in hosts: if host not in host_macs: host_macs[host] = host_mac(host) - command = 'ether-wake -i {0} {1}'.format( + command = '{0} -i {1} {2}'.format( + etherwake, ether_wake_interface, host_macs[host]) if log.isEnabledFor(logging.DEBUG): diff --git a/tests/globals/test_manager.py b/tests/globals/test_manager.py index 71fe825..f569cfe 100644 --- a/tests/globals/test_manager.py +++ b/tests/globals/test_manager.py @@ -60,7 +60,7 @@ class GlobalManager(TestCase): manager.validate_params('test', 'test', {}) manager.validate_params('test', 'test', {'username': 'test'}) manager.validate_params('test', 'test', {'password': 'test'}) - + with MockTransaction: expect(manager).raise_error(403).exactly(2).times() manager.validate_params( @@ -141,13 +141,13 @@ class GlobalManager(TestCase): 'time': time.time() - 6, 'reason': 0, 'host': 'test'}) - assert manager.validate_params('test', 'test', + assert manager.validate_params('test', 'test', {'username': 'test', 'password': 'test', 'time': time.time(), 'reason': 0, 'host': 'test'}) - assert manager.validate_params('test', 'test', + assert manager.validate_params('test', 'test', {'username': 'test', 'password': 'test', 'time': time.time() - 4, @@ -360,7 +360,7 @@ class GlobalManager(TestCase): {'vm1': 512, 'vm2': 1024} def test_switch_hosts_off(self): - db = db_utils.init_db('sqlite:///:memory:') + db = db_utils.init_db('sqlite:///:memory:') with MockTransaction: expect(subprocess).call('ssh h1 "sleep"', shell=True).once() @@ -378,11 +378,15 @@ class GlobalManager(TestCase): manager.switch_hosts_off(db, '', ['h1', 'h2']) def test_switch_hosts_on(self): - db = db_utils.init_db('sqlite:///:memory:') + db = db_utils.init_db('sqlite:///:memory:') with MockTransaction: - expect(subprocess).call('ether-wake -i eth0 mac1', shell=True).once() - expect(subprocess).call('ether-wake -i eth0 mac2', shell=True).once() + expect(subprocess).call(any_of(['ether-wake -i eth0 mac1', + 'etherwake -i eth0 mac1']), + shell=True).once() + expect(subprocess).call(any_of(['ether-wake -i eth0 mac2', + 'etherwake -i eth0 mac2']), + shell=True).once() expect(manager).host_mac('h1').and_return('mac1').once() expect(db).insert_host_states({ 'h1': 1, @@ -390,8 +394,12 @@ class GlobalManager(TestCase): manager.switch_hosts_on(db, 'eth0', {'h2': 'mac2'}, ['h1', 'h2']) with MockTransaction: - expect(subprocess).call('ether-wake -i eth0 mac1', shell=True).once() - expect(subprocess).call('ether-wake -i eth0 mac2', shell=True).once() + expect(subprocess).call(any_of(['ether-wake -i eth0 mac1', + 'etherwake -i eth0 mac1']), + shell=True).once() + expect(subprocess).call(any_of(['ether-wake -i eth0 mac2', + 'etherwake -i eth0 mac2']), + shell=True).once() expect(manager).host_mac('h1').and_return('mac1').once() expect(manager).host_mac('h2').and_return('mac2').once() expect(db).insert_host_states({