Added platform-dependent selection of the etherwake program name: ether-wake for RedHat and CentOS, etherwake for others
This commit is contained in:
parent
86d5ffb59e
commit
620425f10d
@ -84,6 +84,13 @@ from neat.db_utils import *
|
|||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
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 = {
|
ERRORS = {
|
||||||
400: 'Bad input parameter: incorrect or missing parameters',
|
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:
|
for host in hosts:
|
||||||
if host not in host_macs:
|
if host not in host_macs:
|
||||||
host_macs[host] = host_mac(host)
|
host_macs[host] = host_mac(host)
|
||||||
command = 'ether-wake -i {0} {1}'.format(
|
command = '{0} -i {1} {2}'.format(
|
||||||
|
etherwake,
|
||||||
ether_wake_interface,
|
ether_wake_interface,
|
||||||
host_macs[host])
|
host_macs[host])
|
||||||
if log.isEnabledFor(logging.DEBUG):
|
if log.isEnabledFor(logging.DEBUG):
|
||||||
|
@ -60,7 +60,7 @@ class GlobalManager(TestCase):
|
|||||||
manager.validate_params('test', 'test', {})
|
manager.validate_params('test', 'test', {})
|
||||||
manager.validate_params('test', 'test', {'username': 'test'})
|
manager.validate_params('test', 'test', {'username': 'test'})
|
||||||
manager.validate_params('test', 'test', {'password': 'test'})
|
manager.validate_params('test', 'test', {'password': 'test'})
|
||||||
|
|
||||||
with MockTransaction:
|
with MockTransaction:
|
||||||
expect(manager).raise_error(403).exactly(2).times()
|
expect(manager).raise_error(403).exactly(2).times()
|
||||||
manager.validate_params(
|
manager.validate_params(
|
||||||
@ -141,13 +141,13 @@ class GlobalManager(TestCase):
|
|||||||
'time': time.time() - 6,
|
'time': time.time() - 6,
|
||||||
'reason': 0,
|
'reason': 0,
|
||||||
'host': 'test'})
|
'host': 'test'})
|
||||||
assert manager.validate_params('test', 'test',
|
assert manager.validate_params('test', 'test',
|
||||||
{'username': 'test',
|
{'username': 'test',
|
||||||
'password': 'test',
|
'password': 'test',
|
||||||
'time': time.time(),
|
'time': time.time(),
|
||||||
'reason': 0,
|
'reason': 0,
|
||||||
'host': 'test'})
|
'host': 'test'})
|
||||||
assert manager.validate_params('test', 'test',
|
assert manager.validate_params('test', 'test',
|
||||||
{'username': 'test',
|
{'username': 'test',
|
||||||
'password': 'test',
|
'password': 'test',
|
||||||
'time': time.time() - 4,
|
'time': time.time() - 4,
|
||||||
@ -360,7 +360,7 @@ class GlobalManager(TestCase):
|
|||||||
{'vm1': 512, 'vm2': 1024}
|
{'vm1': 512, 'vm2': 1024}
|
||||||
|
|
||||||
def test_switch_hosts_off(self):
|
def test_switch_hosts_off(self):
|
||||||
db = db_utils.init_db('sqlite:///:memory:')
|
db = db_utils.init_db('sqlite:///:memory:')
|
||||||
|
|
||||||
with MockTransaction:
|
with MockTransaction:
|
||||||
expect(subprocess).call('ssh h1 "sleep"', shell=True).once()
|
expect(subprocess).call('ssh h1 "sleep"', shell=True).once()
|
||||||
@ -378,11 +378,15 @@ class GlobalManager(TestCase):
|
|||||||
manager.switch_hosts_off(db, '', ['h1', 'h2'])
|
manager.switch_hosts_off(db, '', ['h1', 'h2'])
|
||||||
|
|
||||||
def test_switch_hosts_on(self):
|
def test_switch_hosts_on(self):
|
||||||
db = db_utils.init_db('sqlite:///:memory:')
|
db = db_utils.init_db('sqlite:///:memory:')
|
||||||
|
|
||||||
with MockTransaction:
|
with MockTransaction:
|
||||||
expect(subprocess).call('ether-wake -i eth0 mac1', shell=True).once()
|
expect(subprocess).call(any_of(['ether-wake -i eth0 mac1',
|
||||||
expect(subprocess).call('ether-wake -i eth0 mac2', shell=True).once()
|
'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('h1').and_return('mac1').once()
|
||||||
expect(db).insert_host_states({
|
expect(db).insert_host_states({
|
||||||
'h1': 1,
|
'h1': 1,
|
||||||
@ -390,8 +394,12 @@ class GlobalManager(TestCase):
|
|||||||
manager.switch_hosts_on(db, 'eth0', {'h2': 'mac2'}, ['h1', 'h2'])
|
manager.switch_hosts_on(db, 'eth0', {'h2': 'mac2'}, ['h1', 'h2'])
|
||||||
|
|
||||||
with MockTransaction:
|
with MockTransaction:
|
||||||
expect(subprocess).call('ether-wake -i eth0 mac1', shell=True).once()
|
expect(subprocess).call(any_of(['ether-wake -i eth0 mac1',
|
||||||
expect(subprocess).call('ether-wake -i eth0 mac2', shell=True).once()
|
'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('h1').and_return('mac1').once()
|
||||||
expect(manager).host_mac('h2').and_return('mac2').once()
|
expect(manager).host_mac('h2').and_return('mac2').once()
|
||||||
expect(db).insert_host_states({
|
expect(db).insert_host_states({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user