summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2013-12-11 12:39:38 -0600
committerGeorge Kraft <george.kraft@calxeda.com>2013-12-11 12:39:38 -0600
commitd9712bb4070d6b86b5a6be97ce346d72d72acb35 (patch)
treeb3e8dddea690a3992b6dac0b669e933344876c6d
parent97127c4f4ff7a8e42347d815ecda95059ed3c084 (diff)
downloadcxmanage-d9712bb4070d6b86b5a6be97ce346d72d72acb35.tar.gz
CXMAN-261: Update Node and Fabric to use Credentials objects
-rw-r--r--cxmanage_api/fabric.py40
-rw-r--r--cxmanage_api/node.py45
-rw-r--r--cxmanage_api/tests/dummy_node.py3
-rw-r--r--cxmanage_api/tests/fabric_test.py9
4 files changed, 45 insertions, 52 deletions
diff --git a/cxmanage_api/fabric.py b/cxmanage_api/fabric.py
index 29156b0..57b2957 100644
--- a/cxmanage_api/fabric.py
+++ b/cxmanage_api/fabric.py
@@ -38,6 +38,7 @@ import re
from cxmanage_api.tasks import DEFAULT_TASK_QUEUE
from cxmanage_api.tftp import InternalTftp
from cxmanage_api.node import Node as NODE
+from cxmanage_api.credentials import Credentials
from cxmanage_api.cx_exceptions import CommandFailedError, TimeoutError, \
IpmiError, TftpException, ParseError
@@ -51,10 +52,8 @@ class Fabric(object):
:param ip_address: The ip_address of ANY known node for the Fabric.
:type ip_address: string
- :param username: The login username credential. [Default admin]
- :type username: string
- :param password: The login password credential. [Default admin]
- :type password: string
+ :param credentials: Login credentials for ECME/Linux
+ :type credentials: Credentials
:param tftp: Tftp server to facilitate IPMI command responses.
:type tftp: `Tftp <tftp.html>`_
:param task_queue: TaskQueue to use for sending commands.
@@ -113,13 +112,12 @@ class Fabric(object):
return function
# pylint: disable=R0913
- def __init__(self, ip_address, username="admin", password="admin",
- tftp=None, ecme_tftp_port=5001, task_queue=None,
- verbose=False, node=None):
+ def __init__(self, ip_address, credentials=None, tftp=None,
+ ecme_tftp_port=5001, task_queue=None, verbose=False,
+ node=None):
"""Default constructor for the Fabric class."""
self.ip_address = ip_address
- self.username = username
- self.password = password
+ self.credentials = Credentials(credentials)
self._tftp = tftp
self.ecme_tftp_port = ecme_tftp_port
self.task_queue = task_queue
@@ -218,16 +216,15 @@ class Fabric(object):
"""Returns a dictionary of nodes reported by the primary node IP"""
new_nodes = {}
node = self.node(
- ip_address=self.ip_address, username=self.username,
- password=self.password, tftp=self.tftp,
- ecme_tftp_port=self.ecme_tftp_port, verbose=self.verbose
+ ip_address=self.ip_address, credentials=self.credentials,
+ tftp=self.tftp, ecme_tftp_port=self.ecme_tftp_port,
+ verbose=self.verbose
)
ipinfo = node.get_fabric_ipinfo()
for node_id, node_address in ipinfo.iteritems():
new_nodes[node_id] = self.node(
- ip_address=node_address, username=self.username,
- password=self.password, tftp=self.tftp,
- ecme_tftp_port=self.ecme_tftp_port,
+ ip_address=node_address, credentials=self.credentials,
+ tftp=self.tftp, ecme_tftp_port=self.ecme_tftp_port,
verbose=self.verbose
)
new_nodes[node_id].node_id = node_id
@@ -901,8 +898,8 @@ class Fabric(object):
return self._run_on_all_nodes(async, "get_ubootenv")
# pylint: disable=R0913
- def get_server_ip(self, interface=None, ipv6=False, user="user1",
- password="1Password", aggressive=False, async=False):
+ def get_server_ip(self, interface=None, ipv6=False, aggressive=False,
+ async=False):
"""Get the server IP address from all nodes. The nodes must be powered
on for this to work.
@@ -918,10 +915,6 @@ class Fabric(object):
:type interface: string
:param ipv6: Return an IPv6 address instead of IPv4.
:type ipv6: boolean
- :param user: Linux username.
- :type user: string
- :param password: Linux password.
- :type password: string
:param aggressive: Discover the IP aggressively (may power cycle node).
:type aggressive: boolean
:param async: Flag that determines if the command result (dictionary)
@@ -932,8 +925,9 @@ class Fabric(object):
:rtype: dictionary or `Task <command.html>`_
"""
- return self._run_on_all_nodes(async, "get_server_ip", interface, ipv6,
- user, password, aggressive)
+ return self._run_on_all_nodes(
+ async, "get_server_ip", interface, ipv6, aggressive
+ )
def get_ipsrc(self):
"""Return the ipsrc for the fabric.
diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py
index 2eb9d11..d88207a 100644
--- a/cxmanage_api/node.py
+++ b/cxmanage_api/node.py
@@ -51,6 +51,7 @@ from cxmanage_api.image import Image as IMAGE
from cxmanage_api.ubootenv import UbootEnv as UBOOTENV
from cxmanage_api.ip_retriever import IPRetriever as IPRETRIEVER
from cxmanage_api.decorators import retry
+from cxmanage_api.credentials import Credentials
from cxmanage_api.cx_exceptions import TimeoutError, NoSensorError, \
SocmanVersionError, FirmwareConfigError, PriorityIncrementError, \
NoPartitionError, TransferFailure, ImageSizeError, \
@@ -67,10 +68,8 @@ class Node(object):
:param ip_address: The ip_address of the Node.
:type ip_address: string
- :param username: The login username credential. [Default admin]
- :type username: string
- :param password: The login password credential. [Default admin]
- :type password: string
+ :param credentials: Login credentials for ECME/Linux
+ :type credentials: Credentials
:param tftp: The internal/external TFTP server to use for data xfer.
:type tftp: `Tftp <tftp.html>`_
:param verbose: Flag to turn on verbose output (cmd/response).
@@ -84,9 +83,9 @@ class Node(object):
"""
# pylint: disable=R0913
- def __init__(self, ip_address, username="admin", password="admin",
- tftp=None, ecme_tftp_port=5001, verbose=False, bmc=None,
- image=None, ubootenv=None, ipretriever=None):
+ def __init__(self, ip_address, credentials=None, tftp=None,
+ ecme_tftp_port=5001, verbose=False, bmc=None, image=None,
+ ubootenv=None, ipretriever=None):
"""Default constructor for the Node class."""
if (not tftp):
tftp = InternalTftp.default()
@@ -102,14 +101,15 @@ class Node(object):
ipretriever = IPRETRIEVER
self.ip_address = ip_address
- self.username = username
- self.password = password
+ self.credentials = Credentials(credentials)
self.tftp = tftp
self.ecme_tftp = ExternalTftp(ip_address, ecme_tftp_port)
self.verbose = verbose
- self.bmc = make_bmc(bmc, hostname=ip_address, username=username,
- password=password, verbose=verbose)
+ self.bmc = make_bmc(
+ bmc, hostname=ip_address, username=self.credentials.ecme_username,
+ password=self.credentials.ecme_password, verbose=verbose
+ )
self.image = image
self.ubootenv = ubootenv
self.ipretriever = ipretriever
@@ -1124,8 +1124,11 @@ communication.
else:
command = ["ipmitool"]
- command += ["-U", self.username, "-P", self.password, "-H",
- self.ip_address]
+ command += [
+ "-U", self.credentials.ecme_username,
+ "-P", self.credentials.ecme_password,
+ "-H", self.ip_address
+ ]
command += ipmitool_args
if (self.verbose):
@@ -1462,8 +1465,7 @@ communication.
return results
- def get_server_ip(self, interface=None, ipv6=False, user="user1",
- password="1Password", aggressive=False):
+ def get_server_ip(self, interface=None, ipv6=False, aggressive=False):
"""Get the IP address of the Linux server. The server must be powered
on for this to work.
@@ -1474,10 +1476,6 @@ communication.
:type interface: string
:param ipv6: Return an IPv6 address instead of IPv4.
:type ipv6: boolean
- :param user: Linux username.
- :type user: string
- :param password: Linux password.
- :type password: string
:param aggressive: Discover the IP aggressively (may power cycle node).
:type aggressive: boolean
@@ -1490,9 +1488,12 @@ obtained.
"""
verbosity = 2 if self.verbose else 0
- retriever = self.ipretriever(self.ip_address, aggressive=aggressive,
- verbosity=verbosity, server_user=user, server_password=password,
- interface=interface, ipv6=ipv6, bmc=self.bmc)
+ retriever = self.ipretriever(
+ self.ip_address, aggressive=aggressive, verbosity=verbosity,
+ server_user=self.credentials.linux_username,
+ server_password=self.credentials.linux_password,
+ interface=interface, ipv6=ipv6, bmc=self.bmc
+ )
retriever.run()
return retriever.server_ip
diff --git a/cxmanage_api/tests/dummy_node.py b/cxmanage_api/tests/dummy_node.py
index 02af2c2..6d54646 100644
--- a/cxmanage_api/tests/dummy_node.py
+++ b/cxmanage_api/tests/dummy_node.py
@@ -128,8 +128,7 @@ class DummyNode(Dummy):
return {}
# pylint: disable=R0913
- def get_server_ip(self, interface=None, ipv6=False, user="user1",
- password="1Password", aggressive=False):
+ def get_server_ip(self, interface=None, ipv6=False, aggressive=False):
"""Simulate get_server_ip(). """
return "192.168.200.1"
diff --git a/cxmanage_api/tests/fabric_test.py b/cxmanage_api/tests/fabric_test.py
index 3863186..757edc1 100644
--- a/cxmanage_api/tests/fabric_test.py
+++ b/cxmanage_api/tests/fabric_test.py
@@ -192,12 +192,11 @@ class FabricTest(unittest.TestCase):
def test_get_server_ip(self):
""" Test get_server_ip command """
- self.fabric.get_server_ip("interface", "ipv6", "user", "password",
- "aggressive")
+ self.fabric.get_server_ip("interface", "ipv6", "aggressive")
for node in self.nodes:
- self.assertEqual(node.method_calls, [call.get_server_ip(
- "interface", "ipv6", "user", "password", "aggressive"
- )])
+ self.assertEqual(node.method_calls,
+ [call.get_server_ip("interface", "ipv6", "aggressive")]
+ )
def test_failed_command(self):
""" Test a failed command """