コード例 #1
0
ファイル: conftest.py プロジェクト: wololowarrior/salt
def bridge_pytest_and_runtests(
    reap_stray_processes,
    base_env_state_tree_root_dir,
    prod_env_state_tree_root_dir,
    base_env_pillar_tree_root_dir,
    prod_env_pillar_tree_root_dir,
    salt_factories,
    salt_mm_master,
    salt_mm_minion,
    salt_mm_sub_master,
    salt_mm_sub_minion,
):
    # Make sure unittest2 uses the pytest generated configuration
    RUNTIME_VARS.RUNTIME_CONFIGS["mm_master"] = freeze(salt_mm_master.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["mm_minion"] = freeze(salt_mm_minion.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["mm_sub_master"] = freeze(salt_mm_sub_master.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["mm_sub_minion"] = freeze(salt_mm_sub_minion.config)

    # Make sure unittest2 classes know their paths
    RUNTIME_VARS.TMP_MM_CONF_DIR = os.path.dirname(salt_mm_master.config["conf_file"])
    RUNTIME_VARS.TMP_MM_MINION_CONF_DIR = os.path.dirname(
        salt_mm_minion.config["conf_file"]
    )
    RUNTIME_VARS.TMP_MM_SUB_CONF_DIR = os.path.dirname(
        salt_mm_sub_master.config["conf_file"]
    )
    RUNTIME_VARS.TMP_MM_SUB_MINION_CONF_DIR = os.path.dirname(
        salt_mm_sub_minion.config["conf_file"]
    )
コード例 #2
0
def mm_bridge_pytest_and_runtests(
        reap_stray_processes, session_mm_conf_dir,
        session_mm_secondary_conf_dir, session_base_env_pillar_tree_root_dir,
        session_base_env_state_tree_root_dir,
        session_prod_env_state_tree_root_dir, session_mm_master_config,
        session_mm_minion_config, session_mm_secondary_master_config,
        session_mm_secondary_minion_config, default_session_daemons):

    # Make sure unittest2 classes know their paths
    RUNTIME_VARS.TMP_MM_CONF_DIR = session_mm_conf_dir.realpath().strpath
    RUNTIME_VARS.TMP_MM_SUB_CONF_DIR = session_mm_secondary_conf_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR = session_mm_secondary_conf_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_PILLAR_TREE = session_base_env_pillar_tree_root_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_STATE_TREE = session_base_env_state_tree_root_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_PRODENV_STATE_TREE = session_prod_env_state_tree_root_dir.realpath(
    ).strpath

    # Make sure unittest2 uses the pytest generated configuration
    RUNTIME_VARS.RUNTIME_CONFIGS['mm_master'] = freeze(
        session_mm_master_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['mm_minion'] = freeze(
        session_mm_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['mm_sub_master'] = freeze(
        session_mm_secondary_master_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['mm_sub_minion'] = freeze(
        session_mm_secondary_minion_config)
コード例 #3
0
    def get_config(config_for, from_scratch=False):
        if from_scratch:
            if config_for in ("master", "syndic_master", "mm_master", "mm_sub_master"):
                return salt.config.master_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                )
            elif config_for in ("minion", "sub_minion"):
                return salt.config.minion_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for),
                    cache_minion_id=False,
                )
            elif config_for in ("syndic",):
                return salt.config.syndic_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for),
                    AdaptedConfigurationTestCaseMixin.get_config_file_path("minion"),
                )
            elif config_for == "client_config":
                return salt.config.client_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path("master")
                )

        if config_for not in RUNTIME_VARS.RUNTIME_CONFIGS:
            if config_for in ("master", "syndic_master", "mm_master", "mm_sub_master"):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.master_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(
                            config_for
                        )
                    )
                )
            elif config_for in ("minion", "sub_minion"):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.minion_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(
                            config_for
                        )
                    )
                )
            elif config_for in ("syndic",):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.syndic_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(
                            config_for
                        ),
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(
                            "minion"
                        ),
                    )
                )
            elif config_for == "client_config":
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.client_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path("master")
                    )
                )
        return RUNTIME_VARS.RUNTIME_CONFIGS[config_for]
コード例 #4
0
 def setUpClass(cls):
     cls._test_config = freeze(
         {
             "comment": "Configuration discarded.",
             "already_configured": False,
             "result": True,
             "diff": (
                 '[edit interfaces xe-0/0/5]+   description "Adding a description";'
             ),
         }
     )
     cls._test_diff = freeze({"diff1": "value"})
コード例 #5
0
    def test_immutabledict_imutability(self):
        data = {
            1: 1,
            2: 2,
            3: {
                3.1: 3.1,
                3.2: 3.2,
                3.3: {3.31: 3.33, 3.32: 3.34, 3.33: [3.331, 3.332, 3.333]},
            },
            4: [4.1, 4.2, 4.3],
        }
        frozen = immutabletypes.freeze(data)
        with self.assertRaises(TypeError):
            frozen[1] = 2

        with self.assertRaises(TypeError):
            fdict = frozen[3]
            fdict[3.1] = 5

        with self.assertRaises(TypeError):
            fdict = frozen[3]
            fdict[3.4] = 3.4

        with self.assertRaises(TypeError):
            frozen[3][3.3][3.32] = 3.99

        with self.assertRaises(TypeError):
            frozen[3][3.3][3.33][0] = 5

        with self.assertRaises(TypeError):
            flist = frozen[4]
            flist[0] = 5
コード例 #6
0
ファイル: runtests.py プロジェクト: mamh-mixed/saltstack-salt
    def lock(self):
        # Late import
        from salt.utils.immutabletypes import freeze

        frozen_vars = freeze(self._vars.copy())
        self._vars = frozen_vars
        self._locked = True
コード例 #7
0
 def test_freeze_list_sum(self):
     lst = [4, 5, 6]
     imt = immutabletypes.freeze([1, 2, 3])
     __add__ = imt + lst
     self.assertEqual(__add__, [1, 2, 3, 4, 5, 6])
     __radd__ = lst + imt
     self.assertEqual(__radd__, [4, 5, 6, 1, 2, 3])
コード例 #8
0
    def test_immutablelist_imutability(self):
        frozen = immutabletypes.freeze([1, 2, 3])
        with self.assertRaises(TypeError):
            frozen[1] = 2

        with self.assertRaises(TypeError):
            frozen[1:-1] = 5
コード例 #9
0
    def test_immutablelist_imutability(self):
        frozen = immutabletypes.freeze([1, 2, 3])
        with self.assertRaises(TypeError):
            frozen[1] = 2

        with self.assertRaises(TypeError):
            frozen[1:-1] = 5
コード例 #10
0
 def test_freeze_list_sum(self):
     lst = [4, 5, 6]
     imt = immutabletypes.freeze([1, 2, 3])
     __add__ = imt + lst
     self.assertEqual(__add__, [1, 2, 3, 4, 5, 6])
     __radd__ = lst + imt
     self.assertEqual(__radd__, [4, 5, 6, 1, 2, 3])
コード例 #11
0
    def get_config(config_for, from_scratch=False):
        if from_scratch:
            if config_for in ('master', 'syndic_master', 'mm_master', 'mm_sub_master'):
                return salt.config.master_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                )
            elif config_for in ('minion', 'sub_minion'):
                return salt.config.minion_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                )
            elif config_for in ('syndic',):
                return salt.config.syndic_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for),
                    AdaptedConfigurationTestCaseMixin.get_config_file_path('minion')
                )
            elif config_for == 'client_config':
                return salt.config.client_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path('master')
                )

        if config_for not in RUNTIME_VARS.RUNTIME_CONFIGS:
            if config_for in ('master', 'syndic_master', 'mm_master', 'mm_sub_master'):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.master_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                    )
                )
            elif config_for in ('minion', 'sub_minion'):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.minion_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                    )
                )
            elif config_for in ('syndic',):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.syndic_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for),
                        AdaptedConfigurationTestCaseMixin.get_config_file_path('minion')
                    )
                )
            elif config_for == 'client_config':
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    salt.config.client_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path('master')
                    )
                )
        return RUNTIME_VARS.RUNTIME_CONFIGS[config_for]
コード例 #12
0
 def __attrs_post_init__(self):
     if self.python_executable is None:
         self.python_executable = sys.executable
     # We really do not want buffered output
     self.environ.setdefault("PYTHONUNBUFFERED", "1")
     # Don't write .pyc files or create them in __pycache__ directories
     self.environ.setdefault("PYTHONDONTWRITEBYTECODE", "1")
     self.config_file = self.config["conf_file"]
     self.config_dir = os.path.dirname(self.config_file)
     self.id = self.config["id"]
     self.config = freeze(self.config)
コード例 #13
0
ファイル: test_formula.py プロジェクト: nicholasmhughes/salt
def set_model():
    return freeze({
        "interfaces": {
            "interface": {
                "Ethernet1": {
                    "config": {
                        "name": "Ethernet1",
                        "description": "Interface Ethernet1",
                    },
                    "subinterfaces": {
                        "subinterface": {
                            "0": {
                                "config": {
                                    "index": 0,
                                    "description": "Subinterface Ethernet1.0",
                                }
                            },
                            "100": {
                                "config": {
                                    "index": 100,
                                    "description":
                                    "Subinterface Ethernet1.100",
                                }
                            },
                            "900": {
                                "config": {
                                    "index": 900,
                                    "description":
                                    "Subinterface Ethernet1.900",
                                }
                            },
                        }
                    },
                },
                "Ethernet2": {
                    "config": {
                        "name": "Ethernet2",
                        "description": "Interface Ethernet2",
                    },
                    "subinterfaces": {
                        "subinterface": {
                            "400": {
                                "config": {
                                    "index": 400,
                                    "description":
                                    "Subinterface Ethernet2.400",
                                }
                            }
                        }
                    },
                },
            }
        }
    })
コード例 #14
0
ファイル: conftest.py プロジェクト: testadactyl/salt
def bridge_pytest_and_runtests(
    reap_stray_processes,
    salt_factories,
    salt_syndic_master_factory,
    salt_syndic_factory,
    salt_master_factory,
    salt_minion_factory,
    salt_sub_minion_factory,
    sshd_config_dir,
):
    # Make sure unittest2 uses the pytest generated configuration
    RUNTIME_VARS.RUNTIME_CONFIGS["master"] = freeze(salt_master_factory.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["minion"] = freeze(salt_minion_factory.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["sub_minion"] = freeze(
        salt_sub_minion_factory.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["syndic_master"] = freeze(
        salt_syndic_master_factory.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["syndic"] = freeze(salt_syndic_factory.config)
    RUNTIME_VARS.RUNTIME_CONFIGS["client_config"] = freeze(
        salt.config.client_config(salt_master_factory.config["conf_file"]))

    # Make sure unittest2 classes know their paths
    RUNTIME_VARS.TMP_ROOT_DIR = str(salt_factories.root_dir.resolve())
    RUNTIME_VARS.TMP_CONF_DIR = os.path.dirname(
        salt_master_factory.config["conf_file"])
    RUNTIME_VARS.TMP_MINION_CONF_DIR = os.path.dirname(
        salt_minion_factory.config["conf_file"])
    RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR = os.path.dirname(
        salt_sub_minion_factory.config["conf_file"])
    RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR = os.path.dirname(
        salt_syndic_master_factory.config["conf_file"])
    RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR = os.path.dirname(
        salt_syndic_factory.config["conf_file"])
    RUNTIME_VARS.TMP_SSH_CONF_DIR = str(sshd_config_dir)
コード例 #15
0
def bridge_pytest_and_runtests(
    reap_stray_processes,
    base_env_state_tree_root_dir,
    prod_env_state_tree_root_dir,
    base_env_pillar_tree_root_dir,
    prod_env_pillar_tree_root_dir,
    salt_factories,
    salt_syndic_master_config,
    salt_syndic_config,
    salt_master_config,
    salt_minion_config,
    salt_sub_minion_config,
):
    # Make sure unittest2 uses the pytest generated configuration
    RUNTIME_VARS.RUNTIME_CONFIGS["master"] = freeze(salt_master_config)
    RUNTIME_VARS.RUNTIME_CONFIGS["minion"] = freeze(salt_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS["sub_minion"] = freeze(salt_sub_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS["syndic_master"] = freeze(
        salt_syndic_master_config)
    RUNTIME_VARS.RUNTIME_CONFIGS["syndic"] = freeze(salt_syndic_config)
    RUNTIME_VARS.RUNTIME_CONFIGS["client_config"] = freeze(
        salt.config.client_config(salt_master_config["conf_file"]))

    # Make sure unittest2 classes know their paths
    RUNTIME_VARS.TMP_ROOT_DIR = salt_factories.root_dir.realpath().strpath
    RUNTIME_VARS.TMP_CONF_DIR = os.path.dirname(
        salt_master_config["conf_file"])
    RUNTIME_VARS.TMP_MINION_CONF_DIR = os.path.dirname(
        salt_minion_config["conf_file"])
    RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR = os.path.dirname(
        salt_sub_minion_config["conf_file"])
    RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR = os.path.dirname(
        salt_syndic_master_config["conf_file"])
    RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR = os.path.dirname(
        salt_syndic_config["conf_file"])
コード例 #16
0
def bridge_pytest_and_runtests(session_root_dir,
                               session_conf_dir,
                               session_secondary_conf_dir,
                               session_syndic_conf_dir,
                               session_master_of_masters_conf_dir,
                               session_state_tree_root_dir,
                               session_pillar_tree_root_dir,
                               session_prod_env_state_tree_root_dir,
                               session_master_config,
                               session_minion_config,
                               session_secondary_minion_config,
                               session_master_of_masters_config,
                               session_syndic_config):

    # Make sure unittest2 classes know their paths
    RUNTIME_VARS.TMP = RUNTIME_VARS.SYS_TMP_DIR = session_root_dir.realpath().strpath
    RUNTIME_VARS.TMP_CONF_DIR = session_conf_dir.realpath().strpath
    RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR = session_secondary_conf_dir.realpath().strpath
    RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR = session_master_of_masters_conf_dir.realpath().strpath
    RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR = session_syndic_conf_dir.realpath().strpath
    RUNTIME_VARS.TMP_PILLAR_TREE = session_pillar_tree_root_dir.realpath().strpath
    RUNTIME_VARS.TMP_STATE_TREE = session_state_tree_root_dir.realpath().strpath
    RUNTIME_VARS.TMP_PRODENV_STATE_TREE = session_prod_env_state_tree_root_dir.realpath().strpath

    # Make sure unittest2 uses the pytest generated configuration
    RUNTIME_VARS.RUNTIME_CONFIGS['master'] = freeze(session_master_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['minion'] = freeze(session_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['sub_minion'] = freeze(session_secondary_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['syndic_master'] = freeze(session_master_of_masters_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['syndic'] = freeze(session_syndic_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['client_config'] = freeze(session_master_config)
コード例 #17
0
def bridge_pytest_and_runtests(
        reap_stray_processes, session_root_dir, session_conf_dir,
        session_secondary_conf_dir, session_syndic_conf_dir,
        session_master_of_masters_conf_dir,
        session_base_env_pillar_tree_root_dir,
        session_base_env_state_tree_root_dir,
        session_prod_env_state_tree_root_dir, session_master_config,
        session_minion_config, session_secondary_minion_config,
        session_master_of_masters_config, session_syndic_config):

    # Make sure unittest2 classes know their paths
    RUNTIME_VARS.TMP_ROOT_DIR = session_root_dir.realpath().strpath
    RUNTIME_VARS.TMP_CONF_DIR = session_conf_dir.realpath().strpath
    RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR = session_secondary_conf_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR = session_master_of_masters_conf_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR = session_syndic_conf_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_PILLAR_TREE = session_base_env_pillar_tree_root_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_STATE_TREE = session_base_env_state_tree_root_dir.realpath(
    ).strpath
    RUNTIME_VARS.TMP_PRODENV_STATE_TREE = session_prod_env_state_tree_root_dir.realpath(
    ).strpath

    # Make sure unittest2 uses the pytest generated configuration
    RUNTIME_VARS.RUNTIME_CONFIGS['master'] = freeze(session_master_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['minion'] = freeze(session_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['sub_minion'] = freeze(
        session_secondary_minion_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['syndic_master'] = freeze(
        session_master_of_masters_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['syndic'] = freeze(session_syndic_config)
    RUNTIME_VARS.RUNTIME_CONFIGS['client_config'] = freeze(
        salt.config.client_config(session_conf_dir.join('master').strpath))

    # Copy configuration files and directories which are not automatically generated
    for entry in os.listdir(RUNTIME_VARS.CONF_DIR):
        if entry in ('master', 'minion', 'sub_minion', 'syndic',
                     'syndic_master', 'proxy'):
            # These have runtime computed values and are handled by pytest-salt fixtures
            continue
        entry_path = os.path.join(RUNTIME_VARS.CONF_DIR, entry)
        if os.path.isfile(entry_path):
            shutil.copy(entry_path,
                        os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry))
        elif os.path.isdir(entry_path):
            shutil.copytree(entry_path,
                            os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry))
コード例 #18
0
ファイル: test_formula.py プロジェクト: nicholasmhughes/salt
def set_defaults():
    return freeze({
        "interfaces": {
            "interface": {
                "*": {
                    "config": {
                        "mtu": 2048,
                        "enabled": True
                    },
                    "subinterfaces": {
                        "subinterface": {
                            "*": {
                                "config": {
                                    "enabled": True
                                }
                            }
                        }
                    },
                }
            }
        }
    })
コード例 #19
0
    def test_immutabledict_imutability(self):
        data = {
            1: 1,
            2: 2,
            3: {
                3.1: 3.1,
                3.2: 3.2,
                3.3: {
                    3.31: 3.33,
                    3.32: 3.34,
                    3.33: [3.331, 3.332, 3.333]
                }
            },
            4: [4.1, 4.2, 4.3]
        }
        frozen = immutabletypes.freeze(data)
        with self.assertRaises(TypeError):
            frozen[1] = 2

        with self.assertRaises(TypeError):
            fdict = frozen[3]
            fdict[3.1] = 5

        with self.assertRaises(TypeError):
            fdict = frozen[3]
            fdict[3.4] = 3.4

        with self.assertRaises(TypeError):
            frozen[3][3.3][3.32] = 3.99

        with self.assertRaises(TypeError):
            frozen[3][3.3][3.33][0] = 5

        with self.assertRaises(TypeError):
            flist = frozen[4]
            flist[0] = 5
コード例 #20
0
ファイル: __init__.py プロジェクト: zxstar/salt
    def transplant_configs(cls, transport="zeromq"):
        os.makedirs(RUNTIME_VARS.TMP_MM_CONF_DIR)
        os.makedirs(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR)
        print(
            " * Transplanting multimaster configuration files to '{0}'".format(
                RUNTIME_VARS.TMP_CONF_DIR))
        tests_known_hosts_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR,
                                              "salt_ssh_known_hosts")

        # Primary master in multimaster environment
        master_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, "master"))
        master_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, "mm_master")))
        master_opts["known_hosts_file"] = tests_known_hosts_file
        master_opts["cachedir"] = "cache"
        master_opts["user"] = RUNTIME_VARS.RUNNING_TESTS_USER
        master_opts["config_dir"] = RUNTIME_VARS.TMP_MM_CONF_DIR
        master_opts["root_dir"] = os.path.join(TMP, "rootdir-multimaster")
        master_opts["pki_dir"] = "pki"
        file_tree = {
            "root_dir": os.path.join(FILES, "pillar", "base", "file_tree"),
            "follow_dir_links": False,
            "keep_newline": True,
        }
        master_opts["ext_pillar"].append({"file_tree": file_tree})

        # Secondary master in multimaster environment
        sub_master_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, "master"))
        sub_master_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, "mm_sub_master")))
        sub_master_opts["known_hosts_file"] = tests_known_hosts_file
        sub_master_opts["cachedir"] = "cache"
        sub_master_opts["user"] = RUNTIME_VARS.RUNNING_TESTS_USER
        sub_master_opts["config_dir"] = RUNTIME_VARS.TMP_MM_SUB_CONF_DIR
        sub_master_opts["root_dir"] = os.path.join(TMP,
                                                   "rootdir-sub-multimaster")
        sub_master_opts["pki_dir"] = "pki"
        sub_master_opts["ext_pillar"].append(
            {"file_tree": copy.deepcopy(file_tree)})

        # Under windows we can't seem to properly create a virtualenv off of another
        # virtualenv, we can on linux but we will still point to the virtualenv binary
        # outside the virtualenv running the test suite, if that's the case.
        try:
            real_prefix = sys.real_prefix
            # The above attribute exists, this is a virtualenv
            if salt.utils.platform.is_windows():
                virtualenv_binary = os.path.join(real_prefix, "Scripts",
                                                 "virtualenv.exe")
            else:
                # We need to remove the virtualenv from PATH or we'll get the virtualenv binary
                # from within the virtualenv, we don't want that
                path = os.environ.get("PATH")
                if path is not None:
                    path_items = path.split(os.pathsep)
                    for item in path_items[:]:
                        if item.startswith(sys.base_prefix):
                            path_items.remove(item)
                    os.environ["PATH"] = os.pathsep.join(path_items)
                virtualenv_binary = salt.utils.path.which("virtualenv")
                if path is not None:
                    # Restore previous environ PATH
                    os.environ["PATH"] = path
                if not virtualenv_binary.startswith(real_prefix):
                    virtualenv_binary = None
            if virtualenv_binary and not os.path.exists(virtualenv_binary):
                # It doesn't exist?!
                virtualenv_binary = None
        except AttributeError:
            # We're not running inside a virtualenv
            virtualenv_binary = None

        # This minion connects to both masters
        minion_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, "minion"))
        minion_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, "mm_minion")))
        minion_opts["cachedir"] = "cache"
        minion_opts["user"] = RUNTIME_VARS.RUNNING_TESTS_USER
        minion_opts["config_dir"] = RUNTIME_VARS.TMP_MM_CONF_DIR
        minion_opts["root_dir"] = os.path.join(TMP, "rootdir-multimaster")
        minion_opts["pki_dir"] = "pki"
        minion_opts["hosts.file"] = os.path.join(TMP, "rootdir", "hosts")
        minion_opts["aliases.file"] = os.path.join(TMP, "rootdir", "aliases")
        if virtualenv_binary:
            minion_opts["venv_bin"] = virtualenv_binary

        # This sub_minion also connects to both masters
        sub_minion_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, "sub_minion"))
        sub_minion_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, "mm_sub_minion")))
        sub_minion_opts["cachedir"] = "cache"
        sub_minion_opts["user"] = RUNTIME_VARS.RUNNING_TESTS_USER
        sub_minion_opts["config_dir"] = RUNTIME_VARS.TMP_MM_SUB_CONF_DIR
        sub_minion_opts["root_dir"] = os.path.join(TMP,
                                                   "rootdir-sub-multimaster")
        sub_minion_opts["pki_dir"] = "pki"
        sub_minion_opts["hosts.file"] = os.path.join(TMP, "rootdir", "hosts")
        sub_minion_opts["aliases.file"] = os.path.join(TMP, "rootdir",
                                                       "aliases")
        if virtualenv_binary:
            sub_minion_opts["venv_bin"] = virtualenv_binary

        if transport == "raet":
            master_opts["transport"] = "raet"
            master_opts["raet_port"] = 64506
            sub_master_opts["transport"] = "raet"
            sub_master_opts["raet_port"] = 64556
            minion_opts["transport"] = "raet"
            minion_opts["raet_port"] = 64510
            sub_minion_opts["transport"] = "raet"
            sub_minion_opts["raet_port"] = 64520
            # syndic_master_opts['transport'] = 'raet'

        if transport == "tcp":
            master_opts["transport"] = "tcp"
            sub_master_opts["transport"] = "tcp"
            minion_opts["transport"] = "tcp"
            sub_minion_opts["transport"] = "tcp"

        # Set up config options that require internal data
        master_opts["pillar_roots"] = sub_master_opts["pillar_roots"] = {
            "base": [
                RUNTIME_VARS.TMP_PILLAR_TREE,
                os.path.join(FILES, "pillar", "base"),
            ]
        }
        minion_opts["pillar_roots"] = {
            "base": [
                RUNTIME_VARS.TMP_PILLAR_TREE,
                os.path.join(FILES, "pillar", "base"),
            ]
        }
        master_opts["file_roots"] = sub_master_opts["file_roots"] = {
            "base": [
                os.path.join(FILES, "file", "base"),
                # Let's support runtime created files that can be used like:
                #   salt://my-temp-file.txt
                RUNTIME_VARS.TMP_STATE_TREE,
            ],
            # Alternate root to test __env__ choices
            "prod": [
                os.path.join(FILES, "file", "prod"),
                RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
            ],
        }
        minion_opts["file_roots"] = {
            "base": [
                os.path.join(FILES, "file", "base"),
                # Let's support runtime created files that can be used like:
                #   salt://my-temp-file.txt
                RUNTIME_VARS.TMP_STATE_TREE,
            ],
            # Alternate root to test __env__ choices
            "prod": [
                os.path.join(FILES, "file", "prod"),
                RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
            ],
        }
        master_opts.setdefault("reactor", []).append({
            "salt/minion/*/start":
            [os.path.join(FILES, "reactor-sync-minion.sls")]
        })
        for opts_dict in (master_opts, sub_master_opts):
            if "ext_pillar" not in opts_dict:
                opts_dict["ext_pillar"] = []
            if salt.utils.platform.is_windows():
                opts_dict["ext_pillar"].append({
                    "cmd_yaml":
                    "type {0}".format(os.path.join(FILES, "ext.yaml"))
                })
            else:
                opts_dict["ext_pillar"].append({
                    "cmd_yaml":
                    "cat {0}".format(os.path.join(FILES, "ext.yaml"))
                })

        # all read, only owner write
        autosign_file_permissions = (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
                                     | stat.S_IWUSR)
        for opts_dict in (master_opts, sub_master_opts):
            # We need to copy the extension modules into the new master root_dir or
            # it will be prefixed by it
            new_extension_modules_path = os.path.join(opts_dict["root_dir"],
                                                      "extension_modules")
            if not os.path.exists(new_extension_modules_path):
                shutil.copytree(
                    os.path.join(INTEGRATION_TEST_DIR, "files",
                                 "extension_modules"),
                    new_extension_modules_path,
                )
            opts_dict["extension_modules"] = os.path.join(
                opts_dict["root_dir"], "extension_modules")

            # Copy the autosign_file to the new  master root_dir
            new_autosign_file_path = os.path.join(opts_dict["root_dir"],
                                                  "autosign_file")
            shutil.copyfile(
                os.path.join(INTEGRATION_TEST_DIR, "files", "autosign_file"),
                new_autosign_file_path,
            )
            os.chmod(new_autosign_file_path, autosign_file_permissions)

        # Point the config values to the correct temporary paths
        for name in ("hosts", "aliases"):
            optname = "{0}.file".format(name)
            optname_path = os.path.join(TMP, name)
            master_opts[optname] = optname_path
            sub_master_opts[optname] = optname_path
            minion_opts[optname] = optname_path
            sub_minion_opts[optname] = optname_path

        master_opts["runtests_conn_check_port"] = get_unused_localhost_port()
        sub_master_opts[
            "runtests_conn_check_port"] = get_unused_localhost_port()
        minion_opts["runtests_conn_check_port"] = get_unused_localhost_port()
        sub_minion_opts[
            "runtests_conn_check_port"] = get_unused_localhost_port()

        for conf in (master_opts, sub_master_opts, minion_opts,
                     sub_minion_opts):
            if "engines" not in conf:
                conf["engines"] = []
            conf["engines"].append({"salt_runtests": {}})

            if "engines_dirs" not in conf:
                conf["engines_dirs"] = []

            conf["engines_dirs"].insert(0, ENGINES_DIR)

            if "log_handlers_dirs" not in conf:
                conf["log_handlers_dirs"] = []
            conf["log_handlers_dirs"].insert(0, LOG_HANDLERS_DIR)
            conf["runtests_log_port"] = SALT_LOG_PORT
            conf["runtests_log_level"] = (
                os.environ.get("TESTS_MIN_LOG_LEVEL_NAME") or "debug")

        # ----- Transcribe Configuration ---------------------------------------------------------------------------->
        computed_config = copy.deepcopy(master_opts)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, "master"),
                "w") as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(master_opts),
                                      wfh,
                                      default_flow_style=False)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, "master"),
                "w") as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(sub_master_opts),
                                      wfh,
                                      default_flow_style=False)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, "minion"),
                "w") as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(minion_opts),
                                      wfh,
                                      default_flow_style=False)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, "minion"),
                "w") as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(sub_minion_opts),
                                      wfh,
                                      default_flow_style=False)
        # <---- Transcribe Configuration -----------------------------------------------------------------------------

        # ----- Verify Environment ---------------------------------------------------------------------------------->
        master_opts = salt.config.master_config(
            os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, "master"))
        sub_master_opts = salt.config.master_config(
            os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, "master"))
        minion_opts = salt.config.minion_config(
            os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, "minion"))
        sub_minion_opts = salt.config.minion_config(
            os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, "minion"))

        RUNTIME_VARS.RUNTIME_CONFIGS["mm_master"] = freeze(master_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS["mm_sub_master"] = freeze(sub_master_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS["mm_minion"] = freeze(minion_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS["mm_sub_minion"] = freeze(sub_minion_opts)

        verify_env(
            [
                os.path.join(master_opts["pki_dir"], "minions"),
                os.path.join(master_opts["pki_dir"], "minions_pre"),
                os.path.join(master_opts["pki_dir"], "minions_rejected"),
                os.path.join(master_opts["pki_dir"], "minions_denied"),
                os.path.join(master_opts["cachedir"], "jobs"),
                os.path.join(master_opts["cachedir"], "raet"),
                os.path.join(master_opts["root_dir"], "cache", "tokens"),
                os.path.join(master_opts["pki_dir"], "accepted"),
                os.path.join(master_opts["pki_dir"], "rejected"),
                os.path.join(master_opts["pki_dir"], "pending"),
                os.path.join(master_opts["cachedir"], "raet"),
                os.path.join(sub_master_opts["pki_dir"], "minions"),
                os.path.join(sub_master_opts["pki_dir"], "minions_pre"),
                os.path.join(sub_master_opts["pki_dir"], "minions_rejected"),
                os.path.join(sub_master_opts["pki_dir"], "minions_denied"),
                os.path.join(sub_master_opts["cachedir"], "jobs"),
                os.path.join(sub_master_opts["cachedir"], "raet"),
                os.path.join(sub_master_opts["root_dir"], "cache", "tokens"),
                os.path.join(sub_master_opts["pki_dir"], "accepted"),
                os.path.join(sub_master_opts["pki_dir"], "rejected"),
                os.path.join(sub_master_opts["pki_dir"], "pending"),
                os.path.join(sub_master_opts["cachedir"], "raet"),
                os.path.join(minion_opts["pki_dir"], "accepted"),
                os.path.join(minion_opts["pki_dir"], "rejected"),
                os.path.join(minion_opts["pki_dir"], "pending"),
                os.path.join(minion_opts["cachedir"], "raet"),
                os.path.join(sub_minion_opts["pki_dir"], "accepted"),
                os.path.join(sub_minion_opts["pki_dir"], "rejected"),
                os.path.join(sub_minion_opts["pki_dir"], "pending"),
                os.path.join(sub_minion_opts["cachedir"], "raet"),
                os.path.dirname(master_opts["log_file"]),
                minion_opts["extension_modules"],
                sub_minion_opts["extension_modules"],
                sub_minion_opts["pki_dir"],
                master_opts["sock_dir"],
                sub_master_opts["sock_dir"],
                sub_minion_opts["sock_dir"],
                minion_opts["sock_dir"],
            ],
            RUNTIME_VARS.RUNNING_TESTS_USER,
            root_dir=master_opts["root_dir"],
        )

        cls.mm_master_opts = master_opts
        cls.mm_sub_master_opts = sub_master_opts
        cls.mm_minion_opts = minion_opts
        cls.mm_sub_minion_opts = sub_minion_opts
コード例 #21
0
ファイル: gitfs.py プロジェクト: zhihuacui/salt
_OPTS = freeze({
    "__role":
    "minion",
    "environment":
    None,
    "pillarenv":
    None,
    "hash_type":
    "sha256",
    "file_roots": {},
    "state_top":
    "top.sls",
    "state_top_saltenv":
    None,
    "renderer":
    "yaml_jinja",
    "renderer_whitelist": [],
    "renderer_blacklist": [],
    "pillar_merge_lists":
    False,
    "git_pillar_base":
    "master",
    "git_pillar_branch":
    "master",
    "git_pillar_env":
    "",
    "git_pillar_fallback":
    "",
    "git_pillar_root":
    "",
    "git_pillar_ssl_verify":
    True,
    "git_pillar_global_lock":
    True,
    "git_pillar_user":
    "",
    "git_pillar_password":
    "",
    "git_pillar_insecure_auth":
    False,
    "git_pillar_privkey":
    "",
    "git_pillar_pubkey":
    "",
    "git_pillar_passphrase":
    "",
    "git_pillar_refspecs": [
        "+refs/heads/*:refs/remotes/origin/*",
        "+refs/tags/*:refs/tags/*",
    ],
    "git_pillar_includes":
    True,
})
コード例 #22
0
ファイル: __init__.py プロジェクト: tj90241/salt
    def transplant_configs(cls, transport='zeromq'):
        os.makedirs(RUNTIME_VARS.TMP_MM_CONF_DIR)
        os.makedirs(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR)
        print(' * Transplanting multimaster configuration files to \'{0}\''.
              format(RUNTIME_VARS.TMP_CONF_DIR))
        tests_known_hosts_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR,
                                              'salt_ssh_known_hosts')

        # Primary master in multimaster environment
        master_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, 'master'))
        master_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, 'mm_master')))
        master_opts['known_hosts_file'] = tests_known_hosts_file
        master_opts['cachedir'] = os.path.join(TMP, 'rootdir_multimaster',
                                               'cache')
        master_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        master_opts['config_dir'] = RUNTIME_VARS.TMP_MM_CONF_DIR
        master_opts['root_dir'] = os.path.join(TMP, 'rootdir-multimaster')
        master_opts['pki_dir'] = os.path.join(TMP, 'rootdir-multimaster',
                                              'pki', 'master')
        file_tree = {
            'root_dir': os.path.join(FILES, 'pillar', 'base', 'file_tree'),
            'follow_dir_links': False,
            'keep_newline': True,
        }
        master_opts['ext_pillar'].append({'file_tree': file_tree})

        # Secondary master in multimaster environment
        sub_master_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, 'master'))
        sub_master_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, 'mm_sub_master')))
        sub_master_opts['known_hosts_file'] = tests_known_hosts_file
        sub_master_opts['cachedir'] = os.path.join(TMP,
                                                   'rootdir-sub-multimaster',
                                                   'cache')
        sub_master_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        sub_master_opts['config_dir'] = RUNTIME_VARS.TMP_MM_SUB_CONF_DIR
        sub_master_opts['root_dir'] = os.path.join(TMP,
                                                   'rootdir-sub-multimaster')
        sub_master_opts['pki_dir'] = os.path.join(TMP,
                                                  'rootdir-sub-multimaster',
                                                  'pki', 'master')
        sub_master_opts['ext_pillar'].append(
            {'file_tree': copy.deepcopy(file_tree)})

        # Under windows we can't seem to properly create a virtualenv off of another
        # virtualenv, we can on linux but we will still point to the virtualenv binary
        # outside the virtualenv running the test suite, if that's the case.
        try:
            real_prefix = sys.real_prefix
            # The above attribute exists, this is a virtualenv
            if salt.utils.is_windows():
                virtualenv_binary = os.path.join(real_prefix, 'Scripts',
                                                 'virtualenv.exe')
            else:
                # We need to remove the virtualenv from PATH or we'll get the virtualenv binary
                # from within the virtualenv, we don't want that
                path = os.environ.get('PATH')
                if path is not None:
                    path_items = path.split(os.pathsep)
                    for item in path_items[:]:
                        if item.startswith(sys.base_prefix):
                            path_items.remove(item)
                    os.environ['PATH'] = os.pathsep.join(path_items)
                virtualenv_binary = salt.utils.which('virtualenv')
                if path is not None:
                    # Restore previous environ PATH
                    os.environ['PATH'] = path
                if not virtualenv_binary.startswith(real_prefix):
                    virtualenv_binary = None
            if virtualenv_binary and not os.path.exists(virtualenv_binary):
                # It doesn't exist?!
                virtualenv_binary = None
        except AttributeError:
            # We're not running inside a virtualenv
            virtualenv_binary = None

        # This minion connects to both masters
        minion_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, 'minion'))
        minion_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, 'mm_minion')))
        minion_opts['cachedir'] = os.path.join(TMP, 'rootdir-multimaster',
                                               'cache')
        minion_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        minion_opts['config_dir'] = RUNTIME_VARS.TMP_MM_CONF_DIR
        minion_opts['root_dir'] = os.path.join(TMP, 'rootdir-multimaster')
        minion_opts['pki_dir'] = os.path.join(TMP, 'rootdir-multimaster',
                                              'pki', 'minion')
        minion_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts')
        minion_opts['aliases.file'] = os.path.join(TMP, 'rootdir', 'aliases')
        if virtualenv_binary:
            minion_opts['venv_bin'] = virtualenv_binary

        # This sub_minion also connects to both masters
        sub_minion_opts = salt.config._read_conf_file(
            os.path.join(RUNTIME_VARS.CONF_DIR, 'sub_minion'))
        sub_minion_opts.update(
            salt.config._read_conf_file(
                os.path.join(RUNTIME_VARS.CONF_DIR, 'mm_sub_minion')))
        sub_minion_opts['cachedir'] = os.path.join(TMP,
                                                   'rootdir-sub-multimaster',
                                                   'cache')
        sub_minion_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        sub_minion_opts['config_dir'] = RUNTIME_VARS.TMP_MM_SUB_CONF_DIR
        sub_minion_opts['root_dir'] = os.path.join(TMP,
                                                   'rootdir-sub-multimaster')
        sub_minion_opts['pki_dir'] = os.path.join(TMP,
                                                  'rootdir-sub-multimaster',
                                                  'pki', 'minion')
        sub_minion_opts['hosts.file'] = os.path.join(TMP, 'rootdir', 'hosts')
        sub_minion_opts['aliases.file'] = os.path.join(TMP, 'rootdir',
                                                       'aliases')
        if virtualenv_binary:
            sub_minion_opts['venv_bin'] = virtualenv_binary

        if transport == 'raet':
            master_opts['transport'] = 'raet'
            master_opts['raet_port'] = 64506
            sub_master_opts['transport'] = 'raet'
            sub_master_opts['raet_port'] = 64556
            minion_opts['transport'] = 'raet'
            minion_opts['raet_port'] = 64510
            sub_minion_opts['transport'] = 'raet'
            sub_minion_opts['raet_port'] = 64520
            # syndic_master_opts['transport'] = 'raet'

        if transport == 'tcp':
            master_opts['transport'] = 'tcp'
            sub_master_opts['transport'] = 'tcp'
            minion_opts['transport'] = 'tcp'
            sub_minion_opts['transport'] = 'tcp'

        # Set up config options that require internal data
        master_opts['pillar_roots'] = sub_master_opts['pillar_roots'] = {
            'base': [
                RUNTIME_VARS.TMP_PILLAR_TREE,
                os.path.join(FILES, 'pillar', 'base'),
            ]
        }
        minion_opts['pillar_roots'] = {
            'base': [
                RUNTIME_VARS.TMP_PILLAR_TREE,
                os.path.join(FILES, 'pillar', 'base'),
            ]
        }
        master_opts['file_roots'] = sub_master_opts['file_roots'] = {
            'base': [
                os.path.join(FILES, 'file', 'base'),
                # Let's support runtime created files that can be used like:
                #   salt://my-temp-file.txt
                RUNTIME_VARS.TMP_STATE_TREE
            ],
            # Alternate root to test __env__ choices
            'prod': [
                os.path.join(FILES, 'file', 'prod'),
                RUNTIME_VARS.TMP_PRODENV_STATE_TREE
            ]
        }
        minion_opts['file_roots'] = {
            'base': [
                os.path.join(FILES, 'file', 'base'),
                # Let's support runtime created files that can be used like:
                #   salt://my-temp-file.txt
                RUNTIME_VARS.TMP_STATE_TREE
            ],
            # Alternate root to test __env__ choices
            'prod': [
                os.path.join(FILES, 'file', 'prod'),
                RUNTIME_VARS.TMP_PRODENV_STATE_TREE
            ]
        }
        master_opts.setdefault('reactor', []).append({
            'salt/minion/*/start':
            [os.path.join(FILES, 'reactor-sync-minion.sls')],
        })
        for opts_dict in (master_opts, sub_master_opts):
            if 'ext_pillar' not in opts_dict:
                opts_dict['ext_pillar'] = []
            if salt.utils.platform.is_windows():
                opts_dict['ext_pillar'].append({
                    'cmd_yaml':
                    'type {0}'.format(os.path.join(FILES, 'ext.yaml'))
                })
            else:
                opts_dict['ext_pillar'].append({
                    'cmd_yaml':
                    'cat {0}'.format(os.path.join(FILES, 'ext.yaml'))
                })

        # all read, only owner write
        autosign_file_permissions = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR
        for opts_dict in (master_opts, sub_master_opts):
            # We need to copy the extension modules into the new master root_dir or
            # it will be prefixed by it
            new_extension_modules_path = os.path.join(opts_dict['root_dir'],
                                                      'extension_modules')
            if not os.path.exists(new_extension_modules_path):
                shutil.copytree(
                    os.path.join(INTEGRATION_TEST_DIR, 'files',
                                 'extension_modules'),
                    new_extension_modules_path)
            opts_dict['extension_modules'] = os.path.join(
                opts_dict['root_dir'], 'extension_modules')

            # Copy the autosign_file to the new  master root_dir
            new_autosign_file_path = os.path.join(opts_dict['root_dir'],
                                                  'autosign_file')
            shutil.copyfile(
                os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_file'),
                new_autosign_file_path)
            os.chmod(new_autosign_file_path, autosign_file_permissions)

        # Point the config values to the correct temporary paths
        for name in ('hosts', 'aliases'):
            optname = '{0}.file'.format(name)
            optname_path = os.path.join(TMP, name)
            master_opts[optname] = optname_path
            sub_master_opts[optname] = optname_path
            minion_opts[optname] = optname_path
            sub_minion_opts[optname] = optname_path

        master_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        sub_master_opts[
            'runtests_conn_check_port'] = get_unused_localhost_port()
        minion_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        sub_minion_opts[
            'runtests_conn_check_port'] = get_unused_localhost_port()

        for conf in (master_opts, sub_master_opts, minion_opts,
                     sub_minion_opts):
            if 'engines' not in conf:
                conf['engines'] = []
            conf['engines'].append({'salt_runtests': {}})

            if 'engines_dirs' not in conf:
                conf['engines_dirs'] = []

            conf['engines_dirs'].insert(0, ENGINES_DIR)

            if 'log_handlers_dirs' not in conf:
                conf['log_handlers_dirs'] = []
            conf['log_handlers_dirs'].insert(0, LOG_HANDLERS_DIR)
            conf['runtests_log_port'] = SALT_LOG_PORT
            conf['runtests_log_level'] = os.environ.get(
                'TESTS_MIN_LOG_LEVEL_NAME') or 'debug'

        # ----- Transcribe Configuration ---------------------------------------------------------------------------->
        computed_config = copy.deepcopy(master_opts)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, 'master'),
                'w') as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(master_opts),
                                      wfh,
                                      default_flow_style=False)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, 'master'),
                'w') as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(sub_master_opts),
                                      wfh,
                                      default_flow_style=False)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, 'minion'),
                'w') as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(minion_opts),
                                      wfh,
                                      default_flow_style=False)
        with salt.utils.files.fopen(
                os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, 'minion'),
                'w') as wfh:
            salt.utils.yaml.safe_dump(copy.deepcopy(sub_minion_opts),
                                      wfh,
                                      default_flow_style=False)
        # <---- Transcribe Configuration -----------------------------------------------------------------------------

        # ----- Verify Environment ---------------------------------------------------------------------------------->
        master_opts = salt.config.master_config(
            os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, 'master'))
        sub_master_opts = salt.config.master_config(
            os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, 'master'))
        minion_opts = salt.config.minion_config(
            os.path.join(RUNTIME_VARS.TMP_MM_CONF_DIR, 'minion'))
        sub_minion_opts = salt.config.minion_config(
            os.path.join(RUNTIME_VARS.TMP_MM_SUB_CONF_DIR, 'minion'))

        RUNTIME_VARS.RUNTIME_CONFIGS['mm_master'] = freeze(master_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['mm_sub_master'] = freeze(sub_master_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['mm_minion'] = freeze(minion_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['mm_sub_minion'] = freeze(sub_minion_opts)

        verify_env(
            [
                os.path.join(master_opts['pki_dir'], 'minions'),
                os.path.join(master_opts['pki_dir'], 'minions_pre'),
                os.path.join(master_opts['pki_dir'], 'minions_rejected'),
                os.path.join(master_opts['pki_dir'], 'minions_denied'),
                os.path.join(master_opts['cachedir'], 'jobs'),
                os.path.join(master_opts['cachedir'], 'raet'),
                os.path.join(master_opts['root_dir'], 'cache', 'tokens'),
                os.path.join(master_opts['pki_dir'], 'accepted'),
                os.path.join(master_opts['pki_dir'], 'rejected'),
                os.path.join(master_opts['pki_dir'], 'pending'),
                os.path.join(master_opts['cachedir'], 'raet'),
                os.path.join(sub_master_opts['pki_dir'], 'minions'),
                os.path.join(sub_master_opts['pki_dir'], 'minions_pre'),
                os.path.join(sub_master_opts['pki_dir'], 'minions_rejected'),
                os.path.join(sub_master_opts['pki_dir'], 'minions_denied'),
                os.path.join(sub_master_opts['cachedir'], 'jobs'),
                os.path.join(sub_master_opts['cachedir'], 'raet'),
                os.path.join(sub_master_opts['root_dir'], 'cache', 'tokens'),
                os.path.join(sub_master_opts['pki_dir'], 'accepted'),
                os.path.join(sub_master_opts['pki_dir'], 'rejected'),
                os.path.join(sub_master_opts['pki_dir'], 'pending'),
                os.path.join(sub_master_opts['cachedir'], 'raet'),
                os.path.join(minion_opts['pki_dir'], 'accepted'),
                os.path.join(minion_opts['pki_dir'], 'rejected'),
                os.path.join(minion_opts['pki_dir'], 'pending'),
                os.path.join(minion_opts['cachedir'], 'raet'),
                os.path.join(sub_minion_opts['pki_dir'], 'accepted'),
                os.path.join(sub_minion_opts['pki_dir'], 'rejected'),
                os.path.join(sub_minion_opts['pki_dir'], 'pending'),
                os.path.join(sub_minion_opts['cachedir'], 'raet'),
                os.path.dirname(master_opts['log_file']),
                minion_opts['extension_modules'],
                sub_minion_opts['extension_modules'],
                sub_minion_opts['pki_dir'],
                master_opts['sock_dir'],
                sub_master_opts['sock_dir'],
                sub_minion_opts['sock_dir'],
                minion_opts['sock_dir'],
            ],
            RUNTIME_VARS.RUNNING_TESTS_USER,
            root_dir=master_opts['root_dir'],
        )

        cls.mm_master_opts = master_opts
        cls.mm_sub_master_opts = sub_master_opts
        cls.mm_minion_opts = minion_opts
        cls.mm_sub_minion_opts = sub_minion_opts
コード例 #23
0
def freeze_logging_options_dict():
    """
    Turn the logging options dictionary into an immutable dictionary
    """
    set_logging_options_dict.__options_dict__ = freeze(
        set_logging_options_dict.__options_dict__)
コード例 #24
0
ファイル: napalm.py プロジェクト: mamh-mixed/saltstack-salt
"""
Base classes for napalm unit tests

:codeauthor: :email:`Anthony Shaw <*****@*****.**>`
"""

from functools import wraps

from salt.utils.immutabletypes import freeze

TEST_INTERFACES = freeze({
    "Management1": {
        "is_up": False,
        "is_enabled": False,
        "description": "",
        "last_flapped": -1,
        "speed": 1000,
        "mac_address": "dead:beef:dead",
    }
})

# Test data
TEST_FACTS = freeze({
    "__opts__": {},
    "OPTIONAL_ARGS": {},
    "uptime": "Forever",
    "UP": True,
    "HOSTNAME": "test-device.com",
    "hostname": "test-device.com",
    "username": "******",
    "os_version": "1.2.3",
コード例 #25
0
ファイル: __init__.py プロジェクト: hackacad/salt
    def transplant_configs(cls, transport='zeromq'):
        if os.path.isdir(RUNTIME_VARS.TMP):
            shutil.rmtree(RUNTIME_VARS.TMP)
        os.makedirs(RUNTIME_VARS.TMP)
        os.makedirs(RUNTIME_VARS.TMP_ROOT_DIR)
        os.makedirs(RUNTIME_VARS.TMP_CONF_DIR)
        os.makedirs(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR)
        os.makedirs(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR)
        os.makedirs(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR)

        print(' * Transplanting configuration files to \'{0}\''.format(RUNTIME_VARS.TMP_CONF_DIR))
        tests_known_hosts_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'salt_ssh_known_hosts')
        with salt.utils.files.fopen(tests_known_hosts_file, 'w') as known_hosts:
            known_hosts.write('')

        # This master connects to syndic_master via a syndic
        master_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'master'))
        master_opts['known_hosts_file'] = tests_known_hosts_file
        master_opts['cachedir'] = 'cache'
        master_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        master_opts['root_dir'] = os.path.join(TMP_ROOT_DIR)
        master_opts['pki_dir'] = 'pki'
        master_opts['syndic_master'] = 'localhost'
        pytest_stop_sending_events_file = os.path.join(TMP_ROOT_DIR, 'pytest_stop_sending_events_file_master')
        with salt.utils.files.fopen(pytest_stop_sending_events_file, 'w') as wfh:
            wfh.write('')
        master_opts['pytest_stop_sending_events_file'] = pytest_stop_sending_events_file

        # This minion connects to master
        minion_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'minion'))
        minion_opts['cachedir'] = 'cache'
        minion_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        minion_opts['root_dir'] = os.path.join(TMP_ROOT_DIR)
        minion_opts['pki_dir'] = 'pki'
        minion_opts['hosts.file'] = os.path.join(TMP_ROOT_DIR, 'hosts')
        minion_opts['aliases.file'] = os.path.join(TMP_ROOT_DIR, 'aliases')

        # This sub_minion also connects to master
        sub_minion_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'sub_minion'))
        sub_minion_opts['cachedir'] = 'cache'
        sub_minion_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        sub_minion_opts['root_dir'] = os.path.join(TMP, 'rootdir-sub-minion')
        sub_minion_opts['pki_dir'] = 'pki'
        sub_minion_opts['hosts.file'] = os.path.join(TMP_ROOT_DIR, 'hosts')
        sub_minion_opts['aliases.file'] = os.path.join(TMP_ROOT_DIR, 'aliases')

        # This is the master of masters
        syndic_master_opts = salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'syndic_master'))
        syndic_master_opts['cachedir'] = 'cache'
        syndic_master_opts['user'] = RUNTIME_VARS.RUNNING_TESTS_USER
        syndic_master_opts['root_dir'] = os.path.join(TMP, 'rootdir-syndic-master')
        syndic_master_opts['pki_dir'] = 'pki'
        pytest_stop_sending_events_file = os.path.join(TMP_ROOT_DIR, 'pytest_stop_sending_events_file_syndic_master')
        with salt.utils.files.fopen(pytest_stop_sending_events_file, 'w') as wfh:
            wfh.write('')
        syndic_master_opts['pytest_stop_sending_events_file'] = pytest_stop_sending_events_file

        # This is the syndic for master
        # Let's start with a copy of the syndic master configuration
        syndic_opts = copy.deepcopy(syndic_master_opts)
        # Let's update with the syndic configuration
        syndic_opts.update(salt.config._read_conf_file(os.path.join(RUNTIME_VARS.CONF_DIR, 'syndic')))
        syndic_opts['cachedir'] = 'cache'
        syndic_opts['root_dir'] = os.path.join(TMP_ROOT_DIR)

        # This proxy connects to master
        proxy_opts = salt.config._read_conf_file(os.path.join(CONF_DIR, 'proxy'))
        proxy_opts['cachedir'] = 'cache'
        # proxy_opts['user'] = running_tests_user
        proxy_opts['root_dir'] = os.path.join(TMP, 'rootdir-proxy')
        proxy_opts['pki_dir'] = 'pki'
        proxy_opts['hosts.file'] = os.path.join(TMP, 'rootdir-proxy', 'hosts')
        proxy_opts['aliases.file'] = os.path.join(TMP, 'rootdir-proxy', 'aliases')

        if transport == 'tcp':
            master_opts['transport'] = 'tcp'
            minion_opts['transport'] = 'tcp'
            sub_minion_opts['transport'] = 'tcp'
            syndic_master_opts['transport'] = 'tcp'
            proxy_opts['transport'] = 'tcp'

        # Set up config options that require internal data
        master_opts['pillar_roots'] = syndic_master_opts['pillar_roots'] = {
            'base': [
                RUNTIME_VARS.TMP_PILLAR_TREE,
                os.path.join(FILES, 'pillar', 'base'),
            ]
        }
        minion_opts['pillar_roots'] = {
            'base': [
                RUNTIME_VARS.TMP_PILLAR_TREE,
                os.path.join(FILES, 'pillar', 'base'),
            ]
        }
        master_opts['file_roots'] = syndic_master_opts['file_roots'] = {
            'base': [
                os.path.join(FILES, 'file', 'base'),
                # Let's support runtime created files that can be used like:
                #   salt://my-temp-file.txt
                RUNTIME_VARS.TMP_STATE_TREE
            ],
            # Alternate root to test __env__ choices
            'prod': [
                os.path.join(FILES, 'file', 'prod'),
                RUNTIME_VARS.TMP_PRODENV_STATE_TREE
            ]
        }
        minion_opts['file_roots'] = {
            'base': [
                os.path.join(FILES, 'file', 'base'),
                # Let's support runtime created files that can be used like:
                #   salt://my-temp-file.txt
                RUNTIME_VARS.TMP_STATE_TREE
            ],
            # Alternate root to test __env__ choices
            'prod': [
                os.path.join(FILES, 'file', 'prod'),
                RUNTIME_VARS.TMP_PRODENV_STATE_TREE
            ]
        }
        master_opts.setdefault('reactor', []).append(
            {
                'salt/minion/*/start': [
                    os.path.join(FILES, 'reactor-sync-minion.sls')
                ],
            }
        )
        master_opts.setdefault('reactor', []).append(
            {
                'salt/test/reactor': [
                    os.path.join(FILES, 'reactor-test.sls')
                ],

            }
        )
        for opts_dict in (master_opts, syndic_master_opts):
            if 'ext_pillar' not in opts_dict:
                opts_dict['ext_pillar'] = []
            if salt.utils.platform.is_windows():
                opts_dict['ext_pillar'].append(
                    {'cmd_yaml': 'type {0}'.format(os.path.join(FILES, 'ext.yaml'))})
            else:
                opts_dict['ext_pillar'].append(
                    {'cmd_yaml': 'cat {0}'.format(os.path.join(FILES, 'ext.yaml'))})

        # all read, only owner write
        autosign_file_permissions = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR
        for opts_dict in (master_opts, syndic_master_opts):
            # We need to copy the extension modules into the new master root_dir or
            # it will be prefixed by it
            new_extension_modules_path = os.path.join(opts_dict['root_dir'], 'extension_modules')
            if not os.path.exists(new_extension_modules_path):
                shutil.copytree(
                    os.path.join(
                        INTEGRATION_TEST_DIR, 'files', 'extension_modules'
                    ),
                    new_extension_modules_path
                )
            opts_dict['extension_modules'] = os.path.join(opts_dict['root_dir'], 'extension_modules')

            # Copy the autosign_file to the new  master root_dir
            new_autosign_file_path = os.path.join(opts_dict['root_dir'], 'autosign_file')
            shutil.copyfile(
                os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_file'),
                new_autosign_file_path
            )
            os.chmod(new_autosign_file_path, autosign_file_permissions)

        # Point the config values to the correct temporary paths
        for name in ('hosts', 'aliases'):
            optname = '{0}.file'.format(name)
            optname_path = os.path.join(TMP, name)
            master_opts[optname] = optname_path
            minion_opts[optname] = optname_path
            sub_minion_opts[optname] = optname_path
            syndic_opts[optname] = optname_path
            syndic_master_opts[optname] = optname_path
            proxy_opts[optname] = optname_path

        master_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        minion_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        sub_minion_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        syndic_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        syndic_master_opts['runtests_conn_check_port'] = get_unused_localhost_port()
        proxy_opts['runtests_conn_check_port'] = get_unused_localhost_port()

        for conf in (master_opts, minion_opts, sub_minion_opts, syndic_opts, syndic_master_opts, proxy_opts):
            if 'engines' not in conf:
                conf['engines'] = []
            conf['engines'].append({'salt_runtests': {}})

            if 'engines_dirs' not in conf:
                conf['engines_dirs'] = []

            conf['engines_dirs'].insert(0, ENGINES_DIR)

            if 'log_handlers_dirs' not in conf:
                conf['log_handlers_dirs'] = []
            conf['log_handlers_dirs'].insert(0, LOG_HANDLERS_DIR)
            conf['runtests_log_port'] = SALT_LOG_PORT

        # ----- Transcribe Configuration ---------------------------------------------------------------------------->
        for entry in os.listdir(RUNTIME_VARS.CONF_DIR):
            if entry in ('master', 'minion', 'sub_minion', 'syndic', 'syndic_master', 'proxy'):
                # These have runtime computed values and will be handled
                # differently
                continue
            entry_path = os.path.join(RUNTIME_VARS.CONF_DIR, entry)
            if os.path.isfile(entry_path):
                shutil.copy(
                    entry_path,
                    os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry)
                )
            elif os.path.isdir(entry_path):
                shutil.copytree(
                    entry_path,
                    os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry)
                )

        for entry in ('master', 'minion', 'sub_minion', 'syndic', 'syndic_master', 'proxy'):
            computed_config = copy.deepcopy(locals()['{0}_opts'.format(entry)])
            with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, entry), 'w') as fp_:
                salt.utils.yaml.safe_dump(computed_config, fp_, default_flow_style=False)
        sub_minion_computed_config = copy.deepcopy(sub_minion_opts)
        with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'minion'), 'w') as wfh:
            salt.utils.yaml.safe_dump(sub_minion_computed_config, wfh, default_flow_style=False)
        shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'master'))

        syndic_master_computed_config = copy.deepcopy(syndic_master_opts)
        with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR, 'master'), 'w') as wfh:
            salt.utils.yaml.safe_dump(syndic_master_computed_config, wfh, default_flow_style=False)
        syndic_computed_config = copy.deepcopy(syndic_opts)
        with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'minion'), 'w') as wfh:
            salt.utils.yaml.safe_dump(syndic_computed_config, wfh, default_flow_style=False)
        shutil.copyfile(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'), os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'master'))
        # <---- Transcribe Configuration -----------------------------------------------------------------------------

        # ----- Verify Environment ---------------------------------------------------------------------------------->
        master_opts = salt.config.master_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master'))
        minion_opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion'))
        syndic_opts = salt.config.syndic_config(
            os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'master'),
            os.path.join(RUNTIME_VARS.TMP_SYNDIC_MINION_CONF_DIR, 'minion'),
        )
        sub_minion_opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_SUB_MINION_CONF_DIR, 'minion'))
        syndic_master_opts = salt.config.master_config(os.path.join(RUNTIME_VARS.TMP_SYNDIC_MASTER_CONF_DIR, 'master'))
        proxy_opts = salt.config.proxy_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'proxy'))

        RUNTIME_VARS.RUNTIME_CONFIGS['master'] = freeze(master_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['minion'] = freeze(minion_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['syndic'] = freeze(syndic_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['sub_minion'] = freeze(sub_minion_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['syndic_master'] = freeze(syndic_master_opts)
        RUNTIME_VARS.RUNTIME_CONFIGS['proxy'] = freeze(proxy_opts)

        verify_env([os.path.join(master_opts['pki_dir'], 'minions'),
                    os.path.join(master_opts['pki_dir'], 'minions_pre'),
                    os.path.join(master_opts['pki_dir'], 'minions_rejected'),
                    os.path.join(master_opts['pki_dir'], 'minions_denied'),
                    os.path.join(master_opts['cachedir'], 'jobs'),
                    os.path.join(master_opts['root_dir'], 'cache', 'tokens'),
                    os.path.join(syndic_master_opts['pki_dir'], 'minions'),
                    os.path.join(syndic_master_opts['pki_dir'], 'minions_pre'),
                    os.path.join(syndic_master_opts['pki_dir'], 'minions_rejected'),
                    os.path.join(syndic_master_opts['cachedir'], 'jobs'),
                    os.path.join(syndic_master_opts['root_dir'], 'cache', 'tokens'),
                    os.path.join(master_opts['pki_dir'], 'accepted'),
                    os.path.join(master_opts['pki_dir'], 'rejected'),
                    os.path.join(master_opts['pki_dir'], 'pending'),
                    os.path.join(syndic_master_opts['pki_dir'], 'accepted'),
                    os.path.join(syndic_master_opts['pki_dir'], 'rejected'),
                    os.path.join(syndic_master_opts['pki_dir'], 'pending'),

                    os.path.join(minion_opts['pki_dir'], 'accepted'),
                    os.path.join(minion_opts['pki_dir'], 'rejected'),
                    os.path.join(minion_opts['pki_dir'], 'pending'),
                    os.path.join(sub_minion_opts['pki_dir'], 'accepted'),
                    os.path.join(sub_minion_opts['pki_dir'], 'rejected'),
                    os.path.join(sub_minion_opts['pki_dir'], 'pending'),
                    os.path.dirname(master_opts['log_file']),
                    minion_opts['extension_modules'],
                    sub_minion_opts['extension_modules'],
                    sub_minion_opts['pki_dir'],
                    master_opts['sock_dir'],
                    syndic_master_opts['sock_dir'],
                    sub_minion_opts['sock_dir'],
                    minion_opts['sock_dir'],
                    RUNTIME_VARS.TMP_STATE_TREE,
                    RUNTIME_VARS.TMP_PILLAR_TREE,
                    RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
                    TMP,
                    ],
                   RUNTIME_VARS.RUNNING_TESTS_USER,
                   root_dir=master_opts['root_dir'],
                   )

        cls.master_opts = master_opts
        cls.minion_opts = minion_opts
        # cls.proxy_opts = proxy_opts
        cls.sub_minion_opts = sub_minion_opts
        cls.syndic_opts = syndic_opts
        cls.syndic_master_opts = syndic_master_opts
        cls.proxy_opts = proxy_opts
コード例 #26
0
    def setUpClass(cls):
        cls.model = freeze(
            {
                "interfaces": {
                    "interface": {
                        "Ethernet1": {
                            "config": {
                                "name": "Ethernet1",
                                "description": "Interface Ethernet1",
                            },
                            "subinterfaces": {
                                "subinterface": {
                                    "0": {
                                        "config": {
                                            "index": 0,
                                            "description": "Subinterface Ethernet1.0",
                                        }
                                    },
                                    "100": {
                                        "config": {
                                            "index": 100,
                                            "description": "Subinterface Ethernet1.100",
                                        }
                                    },
                                    "900": {
                                        "config": {
                                            "index": 900,
                                            "description": "Subinterface Ethernet1.900",
                                        }
                                    },
                                }
                            },
                        },
                        "Ethernet2": {
                            "config": {
                                "name": "Ethernet2",
                                "description": "Interface Ethernet2",
                            },
                            "subinterfaces": {
                                "subinterface": {
                                    "400": {
                                        "config": {
                                            "index": 400,
                                            "description": "Subinterface Ethernet2.400",
                                        }
                                    }
                                }
                            },
                        },
                    }
                }
            }
        )

        cls.defaults = freeze(
            {
                "interfaces": {
                    "interface": {
                        "*": {
                            "config": {"mtu": 2048, "enabled": True},
                            "subinterfaces": {
                                "subinterface": {"*": {"config": {"enabled": True}}}
                            },
                        }
                    }
                }
            }
        )