ocpnetsplit package¶
ocpnetsplit.machineconfig module¶
This module generates MachineConfig
to deploy network-split systemd units,
which implements the network split functionality.
References:
- ocpnetsplit.machineconfig.create_file_dict(basename, content, target_dir='/etc')¶
Create Ignition config spec for given file basename and content, to be used in a
MachineConfig
spec. File will be placed giventarget_dir
, but note that MCO can only change files in/etc
and/var
directories.- Parameters:
basename (str) – basename of the file
content (str) – content of the file
target_dir (str) – absolute path where to place the file, eg.
/etc
- Returns:
Ignition storage file config spec
- Return type:
dict
- Raises:
ValueError – if given
basename
ortarget_dir
is invalid
- ocpnetsplit.machineconfig.create_latency_mc_dict(role, latency, latency_spec=None)¶
Create
MachineConfig
dict with latency systemd units and scripts.- Parameters:
mcp (string) – name of
MachineConfig
role (and alsoMachineConfigPool
) where theMachineConfig
generated by this function should be deployed. Usuallymaster
orworker
.latency (int) – default zone latency created via Linux Traffic Control in ms
( (latency_spec) – py:class`ocpnetsplit.zone.ZoneLatSpec`): specific latency between given zones (optional).
- Returns:
MachineConfig dict
- Return type:
dict
- ocpnetsplit.machineconfig.create_script_dict(script_name)¶
Create file dict with given shell script from ocpnetsplit module.
- Parameters:
script_name (string) – name of the shell script
- Returns:
Ignition storage file config spec
- Return type:
dict
- ocpnetsplit.machineconfig.create_split_mc_dict(role)¶
Create
MachineConfig
dict with network-split systemd units and scripts.- Parameters:
mcp (string) – name of
MachineConfig
role (and alsoMachineConfigPool
) where theMachineConfig
generated by this function should be deployed. Usuallymaster
orworker
.- Returns:
MachineConfig dict
- Return type:
dict
- ocpnetsplit.machineconfig.create_systemdunit_dict(unit_filename)¶
Create file dict with given systemd unit file from ocpnetsplit module.
- Parameters:
unit_filename (string) – name of the systemd unit file
- Returns:
Ignition storage file config spec
- Return type:
dict
- ocpnetsplit.machineconfig.create_unit_dict(name, content)¶
Create Ignition config spec for given systemd unit name and content, to be used in a
MachineConfig
spec.- Parameters:
name (str) – name of systemd unit
content (str) – content of the file
- Returns:
Ignition systemd unit config spec
- Return type:
dict
- ocpnetsplit.machineconfig.create_zone_mc_dict(role, zone_env)¶
Create
MachineConfig
dict with network zone config env file.- Parameters:
mcp (string) – name of
MachineConfig
role (and alsoMachineConfigPool
) where theMachineConfig
generated by this function should be deployed. Usuallymaster
orworker
.zone_env (string) – content of
network-split.env
file with zone configuration, as created byocpnetsplit.zone.ZoneConfig.get_env_file()
- Returns:
MachineConfig dict
- Return type:
dict
- ocpnetsplit.machineconfig.get_new_mc(role, name_suffix, priority=99)¶
Initialize new (almost empty) MachineConfig dict.
- Parameters:
role (string) – name of
MachineConfig
rolename_suffix (string) – suffix of resulting MachineConfig name
ocpnetsplit.main module¶
Module with a public API of ocp-network-split project. One can either use the command line tools (as implemented via main functions in this module), or to use the python functions defined here directly.
- ocpnetsplit.main.check_split(nodes, split_name, use_ssh=False)¶
Checks status of split via
systemctl list-timers
on all nodes of the cluster.- Parameters:
nodes (list) – list of all nodes from all zones
split_name (str) – network split configuration specification, eg.
ab
, seeocpnetsplit.zone.NETWORK_SPLITS
constantuse_ssh (bool) – if true, connect to the nodes via ssh; use oc debug node otherwise
- Raises:
ValueError – when invalid
split_name
is specified
- ocpnetsplit.main.get_networksplit_mc_spec(zone_env=None, split=False, latency=0, latency_spec=None)¶
Create
MachineConfig
spec to install network split firewall tweaking script and unit files on all cluster nodes.- Parameters:
zone_env (str) – content of firewall zone env file specifying node ip addresses for each cluster zone, as created by
ocpnetsplit.zone.ZoneConfig.get_env_file()
split (bool) – when true, support for net splits will be included
latency (int) – default zone latency created via Linux Traffic Control in ms, when the value is zero, support for latency is not included
( (latency_spec) – py:class`ocpnetsplit.zone.ZoneLatSpec`): specific latency between given zones (optional).
- Returns:
list of dictionaries with
MachineConfig
spec- Return type:
machineconfig_spec
- ocpnetsplit.main.get_zone_config(zone_a, zone_b, zone_c, zone_x_addrs=None)¶
For each valid ocp-network-split zone name (see
ocpnetsplit.zone.ZONES
), translate it’s giventopology.kubernetes.io/zone
label into list of ip addresses of all nodes in the zone.- Parameters:
zone_a (str) – value of zone
a
labelzone_b (str) – value of zone
b
labelzone_c (str) – value of zone
c
labelzone_x_addrs (list) – list of ip addresses in external zone
x
- Returns:
- object with list of node ip addresses for each zone name
ocp network split works with (
a
,b
, …), seeocpnetsplit.zone.ZONES
).
- Return type:
- ocpnetsplit.main.get_zone_config_fromfile(file_content, translate_hostname=True)¶
Get zone config from ini file, which contains node fqdn entries for each zone.
- ocpnetsplit.main.main_multisetup()¶
Simple multi cluster version of command line interface to generate MachineConfig yaml and env file to deploy on OCP/Ceph clusters.
Example usage:
$ ocp-network-split-multisetup zones.ini --mc mc.yaml --env network-split.env
- ocpnetsplit.main.main_sched()¶
Simple command line interface to schedule given cluster network split.
Example usage:
$ ocp-network-split-sched ab-bc -t 2021-03-18T18:45 --split-len 30 $ ocp-network-split-sched ab-bc
- ocpnetsplit.main.main_setup()¶
Simple command line interface to generate MachineConfig yaml to deploy to make scheduling network splits possible.
Example usage:
$ ocp-network-split-setup -a arbiter -b d1 -c d2 -o mc.yaml $ oc create -f mc.yaml $ oc get mcp
- ocpnetsplit.main.run_ssh_node(cmd_list, node, timeout=600)¶
Run given command on given node via ssh assuming connection details like username and keys are specified via ~/.ssh/config file.
- Parameters:
cmd_list (list) – a command to run, eg.
["uname", "-a"]
will executeuname -a
process on the nodenode (str) – hostname of k8s node where to execute the command
timeout (int) – command timeout specified in seconds, optional
- Returns:
ssh stdout, ssh souterr
- Return type:
tuple
- ocpnetsplit.main.schedule_split(nodes, split_name, target_dt, target_length, use_ssh=False)¶
Schedule start and stop of network split on all nodes of the cluster.
- Parameters:
nodes (list) – list of all nodes from all zones
split_name (str) – network split configuration specification, eg.
ab
, seeocpnetsplit.zone.NETWORK_SPLITS
constanttarget_dt (datetime) – requested start time of the network split
target_length (int) – number of minutes specifying how long the network split configuration should be active
use_ssh (bool) – if true, connect to the nodes via ssh; use oc debug node otherwise
- Raises:
ValueError – in case invalid
split_name
ortarget_dt
is specified.
ocpnetsplit.ocp module¶
- ocpnetsplit.ocp.get_all_node_ip_addrs(node, kubeconfig=None, oc_executable=None)¶
Get all ip addresses (both internal and external) of given node.
- Parameters:
node (str) – name of OCP node
kubeconfig (str) – file path to kubeconfig (optional, use only if you need to override the default)
oc_executable (str) – file path of oc command (optional, use only if you need to override the default)
- Returns:
node ip addressess (as strings)
- Return type:
list
- ocpnetsplit.ocp.list_cluster_nodes(zone_name=None, kubeconfig=None, oc_executable=None)¶
Get cluster nodes of a whole cluster or from given zone only.
- Parameters:
zone_name (str) – name of k8s topology zone to list nodes within, if not specified, nodes from whole cluster will be listed
kubeconfig (str) – file path to kubeconfig (optional, use only if you need to override the default)
oc_executable (str) – file path of oc command (optional, use only if you need to override the default)
- Returns:
node ip addressess (as strings)
- Return type:
list
- ocpnetsplit.ocp.run_oc(cmd_list, kubeconfig=None, oc_executable=None, timeout=600)¶
Run given oc command and log all it’s output.
- Parameters:
cmd_list (list) – oc command to run, eg.
["get", "nodes"]
will executeoc get nodes
processtimeout (int) – command timeout specified in seconds, optional
kubeconfig (str) – file path to kubeconfig (optional, use only if you need to override the default)
oc_executable (str) – file path of oc command (optional, use only if you need to override the default)
- Returns:
stdout, stderr of the command executed
- Return type:
tuple
- ocpnetsplit.ocp.run_oc_debug_node(cmd_list, node, kubeconfig=None, oc_executable=None)¶
Run given command on given node via oc debug node.
- Parameters:
cmd_list (list) – a command to run, eg.
["uname", "-a"]
will executeuname -a
process on the nodenode (str) – name of k8s node where to execute the command, with or without
node/
prefixkubeconfig (str) – file path to kubeconfig (optional, use only if you need to override the default)
oc_executable (str) – file path of oc command (optional, use only if you need to override the default)
- Returns:
- cmd_out (combined stdout and stderr of the executed command),
oc_out (output from oc debug process itself)
- Return type:
tuple
ocpnetsplit.zone module¶
- ocpnetsplit.zone.NETWORK_SPLITS = ('ab', 'bc', 'ab-bc', 'ab-ac', 'ax', 'ax-bx-cx')¶
Available network split configurations. For every valid network split value, there is a systemd timer unit named
network-split-{split}-setup@.timer
. Network split configuration consists of list of zone tuples, where each zone tuple represents a disrupted zone connection.
- ocpnetsplit.zone.ZONES = ('a', 'b', 'c', 'x')¶
Stable zone identifiers as defined and used by ocp-network-split.
- class ocpnetsplit.zone.ZoneConfig¶
Bases:
object
ZoneConfig is tracking ip addresses of nodes in each cluster zone.
- add_node(zone, node)¶
Add a node ip address into a zone.
- Parameters:
zone (str) – zone identification (one of
ZONES
)node (str) – ip address of a node
- add_nodes(zone, nodes)¶
Add list of node ip addresses into a zone.
- Parameters:
zone (str) – zone identification (one of
ZONES
)nodes (list) – list of string representation of node ip addresses
- get_env_file()¶
Generate content of env file for firewall script.
- Returns:
content of firewall environment file with zone configuration
- Return type:
str
- get_nodes(zone=None)¶
Return set of node ip addresses in given zone.
- Parameters:
zone (str) – zone identification (one of
ZONES
), if notspecified
be (zone filtering is not applied and all nodes will)
returned
- Returns:
string representation of node ip addresses of given zone
- Return type:
list
- class ocpnetsplit.zone.ZoneLatSpec(**kwargs)¶
Bases:
object
Describe latency values between given zones.
Validation of input latency spec is necessary to catch mistakes as early as possible (debugging the problem later on a live cluster increases cost of debugging and a fix significantly).
- get_cli_args()¶
Generate command line arguments for network-latency.sh script representing latency spec of this object.
- load_arguments(latency_spec)¶
Load latency spec from the given list produced by argparse parser.
- Parameters:
latency_spec (list) – List of latency specs from argument parser. Eg.:
['ab=10', 'bc=10']
.
- load_dict(latency_spec)¶
Load latency spec from the given dict.
- Parameters:
latency_spec (dict) – specific latency between given zones, for
zones (example {'ab'=11} will represent 22ms RTT latency between)
b. (a and)