Enable time-sync for non-Fuel-based environments

Change-Id: I705ce3bd474bd12971713f06e3a892a2f04c3fef
This commit is contained in:
Dennis Dmitriev 2017-05-25 18:24:03 +03:00
parent 266437f8c9
commit 5d68ed0fa3
3 changed files with 105 additions and 9 deletions

View File

@ -172,6 +172,31 @@ class DevopsEnvironment(object):
password=password,
keys=self.get_private_keys()))
def find_node_ip(self, node_name):
node = self.get_node(name=node_name)
for interface in node.interfaces:
ip = interface.address_set.get(interface=interface).ip_address
try:
helpers.wait_tcp(
host=ip, port=node.ssh_port, timeout=10,
timeout_msg=("Node {ip} is not accessible by SSH."
.format(ip=ip)))
return ip
except error.TimeoutError:
pass
raise error.DevopsError("Cannot find SSH endpoint for node {0}"
.format(node.name))
def find_node_remote(self, node_name,
login=settings.SSH_SLAVE_CREDENTIALS['login'],
password=settings.SSH_SLAVE_CREDENTIALS['password']):
ip = self.find_node_ip(node_name)
return ssh_client.SSHClient(
ip,
auth=ssh_client.SSHAuth(
username=login,
password=password))
def sync_time(self, node_names=None, skip_sync=False):
"""Synchronize time on nodes
@ -183,13 +208,21 @@ class DevopsEnvironment(object):
node_names = [node.name for node in self.get_active_nodes()]
group = ntp.GroupNtpSync()
for node_name in node_names:
if node_name == 'admin':
remote = self.get_admin_remote()
else:
remote = self.get_node_remote(node_name=node_name)
group.add_node(remote, node_name)
if self.has_admin():
# Assume that the node with name 'admin' is a Fuel master node
for node_name in node_names:
if node_name == 'admin':
remote = self.get_admin_remote()
else:
remote = self.get_node_remote(node_name=node_name)
group.add_node(remote, node_name)
else:
# There is no FuelAdmin node, fallback to trying assigned
# addresses.
for node_name in node_names:
remote = self.find_node_remote(node_name=node_name)
group.add_node(remote, node_name)
with group:
if not skip_sync:

View File

@ -482,6 +482,46 @@ class L2NetworkDevice(base.ParamedModel, base.BaseModel):
class NetworkConfig(models.Model):
"""Metadata that describes desired interfaces configuration
When envrironment hardware have been created/adopted,
user may want to execute some post-provisioning steps
to configure interfaces respecting the current network topology.
This metadata helps to describe the expected configuration
that can be taken by any 3rd-party component to perform these steps.
In fuel-devops, this data is not used, so you can skip this object
if network interfaces are configured using some different inventory.
Template example (network_config):
---------------------------------
- name: some_node_name
params:
...
interfaces:
- label: eth0
- label: eth1
- label: eth2
network_config:
eth0: # matches the first interface name
networks:
- admin # expecting interface configuration
# (vlan, ip, ) for network with name 'admin'
# in your inventory.
bond0:
networks:
- control # expecting interface configuration
# (vlan, ip, ) for network with name 'admin'
# in your inventory.
aggregation: active-backup # use 'aggregation' to determine
# that bond0 is a bond interface.
parents: # Slave interfaces for creating this 'bond0'.
- eth1
- eth2
"""
class Meta(object):
db_table = 'devops_network_config'
app_label = 'devops'
@ -494,6 +534,32 @@ class NetworkConfig(models.Model):
class Interface(base.ParamedModel):
"""Describes a network interface configuration
Specify the abstract label of the interface (you can use labels
that match the real interface names or use any suitable names).
'l2_network_device' describes the switch name (virtual or hardware)
to which the interface is connected.
'features' is a json list with any strings you want use to mark
interfaces with specific features and use these marks in 3rd-party
libraries to perform highlevel configuration of the right interfaces
for your product.
Template example (interfaces):
---------------------------------
- name: some_node_name
params:
...
interfaces:
- label: iface0
l2_network_device: admin
- label: iface1
l2_network_device: data
mac_address: !os_env IFACE_MAC_ADDRESS, 00:11:22:33:44:55
features: ['dpdk', 'dpdk_pci: 0000:05:00.1']
"""
class Meta(object):
db_table = 'devops_interface'
app_label = 'devops'

View File

@ -177,9 +177,6 @@ class Shell(object):
print(ap + ": " + ' '.join(n_ips))
def do_time_sync(self):
if not self.env.has_admin():
print('There is no FuelAdmin node. It is impossible to sync time')
return
node_name = self.params.node_name
node_names = [node_name] if node_name else None
cur_time = self.env.get_curr_time(node_names)