Exemple #1
0
 def test_get_default_network(self):
     """
     Ensures default network values are properly parsed
     """
     default_network = config_utils.get_default_network(self.config)
     expected = self.network_list[0][consts.DFLT_NET_KEY]
     self.assertEqual(expected, default_network)
def delete_default_weave_interface(k8s_conf):
    """
    This function is used to delete default weave interface
    """
    if config_utils.get_networking_plugin(k8s_conf) == consts.WEAVE_TYPE:
        network_name = config_utils.get_default_network(
            k8s_conf)[consts.NETWORK_NAME_KEY]
        ansible_utils.apply_playbook(
            consts.K8_DELETE_WEAVE_INTERFACE, variables={
                'networkName': network_name,
                'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(
                    k8s_conf)})
def __create_default_network_multus(k8s_conf):
    """
    This function is used to create default network
    """
    networking_plugin = config_utils.get_networking_plugin(k8s_conf)
    if networking_plugin != "none":
        default_network = config_utils.get_default_network(k8s_conf)
        if (networking_plugin == consts.WEAVE_TYPE or
                networking_plugin == consts.FLANNEL_TYPE and default_network):
            aconf.create_default_network(k8s_conf)
        else:
            logger.info('Cannot create default network as default networking '
                        'plugin is other than flannel/weave')
def validate_default_network_params(config):
    """
    Checks the presence of default network tag and its parameters
    """
    logger.info("checking def networks  params")
    default_net = config_utils.get_default_network(config)
    if not default_net:
        raise ValidationException('Default network must be defined')

    validate_dict_data(default_net, consts.NET_PLUGIN_KEY)
    validate_dict_data(default_net, consts.MASTER_PLUGIN_KEY)
    validate_dict_data(default_net, consts.SRVC_SUB_KEY)
    validate_dict_data(default_net, consts.POD_SUB_KEY)
    validate_dict_data(default_net, consts.NETWORK_NAME_KEY)
Exemple #5
0
def create_default_network(k8s_conf):
    default_network = config_utils.get_default_network(k8s_conf)
    network_name = default_network.get(consts.NETWORK_NAME_KEY)
    if not network_name:
        raise Exception('no network name in [%s]', default_network)

    master_plugin = default_network.get(consts.MASTER_PLUGIN_KEY)
    networking_plugin = config_utils.get_networking_plugin(k8s_conf)
    pb_vars = {
        'networkName': network_name,
        'masterPlugin': master_plugin,
        'networking_plugin': networking_plugin,
        'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(k8s_conf),
    }
    ansible_utils.apply_playbook(consts.K8_CREATE_DEFAULT_NETWORK,
                                 variables=pb_vars)
def ismaster_count_for_deployment(config):
    """
   Checks the presence of master f*g must be true atleast once in deployment
    """
    master_count = 0
    dflt_net = config_utils.get_default_network(config)
    if config_utils.bool_val(dflt_net[consts.MASTER_PLUGIN_KEY]):
        master_count += 1

    multus_nets = config_utils.get_multus_cni_cfgs(config)
    for multus_net in multus_nets:
        if consts.FLANNEL_NET_TYPE in multus_net:
            networks = multus_net[consts.FLANNEL_NET_TYPE]
            for network in networks:
                validate_dict_data(network, consts.FLANNEL_NET_DTLS_KEY)
                details = network[consts.FLANNEL_NET_DTLS_KEY]
                if config_utils.bool_val(details[consts.MASTER_PLUGIN_KEY]):
                    master_count += 1
        if consts.WEAVE_NET_TYPE in multus_net:
            networks = multus_net[consts.WEAVE_NET_TYPE]
            for network in networks:
                validate_dict_data(network, consts.WEAVE_NET_DTLS_KEY)
                details = network[consts.WEAVE_NET_DTLS_KEY]
                if config_utils.bool_val(details[consts.MASTER_PLUGIN_KEY]):
                    master_count += 1
        if consts.MACVLAN_NET_TYPE in multus_net:
            networks = multus_net[consts.MACVLAN_NET_TYPE]
            for network in networks:
                validate_dict_data(network, consts.MACVLAN_NET_DTLS_KEY)
                details = network[consts.MACVLAN_NET_DTLS_KEY]
                if config_utils.bool_val(details[consts.MASTER_PLUGIN_KEY]):
                    master_count += 1
        if consts.SRIOV_NET_TYPE in multus_net:
            net_hosts = multus_net[consts.SRIOV_NET_TYPE]
            for net_host in net_hosts:
                validate_dict_data(net_host, consts.HOST_KEY)
                host_conf = net_host[consts.HOST_KEY]
                validate_dict_data(host_conf, consts.SRIOV_NETWORKS_KEY)
                networks = host_conf[consts.SRIOV_NETWORKS_KEY]
                for network in networks:
                    if config_utils.bool_val(
                            network[consts.MASTER_PLUGIN_KEY]):
                        master_count += 1

    if master_count > 1:
        raise ValidationException('isMaster is present more than once')