def __init__(self, _getpwnam=pwd.getpwnam, _getgrnam=grp.getgrnam): """Initialize the resolver. """ # Daemon pairs self.masterd_uid = GetUid(constants.MASTERD_USER, _getpwnam) self.masterd_gid = GetGid(constants.MASTERD_GROUP, _getgrnam) self.confd_uid = GetUid(constants.CONFD_USER, _getpwnam) self.confd_gid = GetGid(constants.CONFD_GROUP, _getgrnam) self.wconfd_uid = GetUid(constants.WCONFD_USER, _getpwnam) self.wconfd_gid = GetGid(constants.WCONFD_GROUP, _getgrnam) self.luxid_uid = GetUid(constants.LUXID_USER, _getpwnam) self.luxid_gid = GetGid(constants.LUXID_GROUP, _getgrnam) self.rapi_uid = GetUid(constants.RAPI_USER, _getpwnam) self.rapi_gid = GetGid(constants.RAPI_GROUP, _getgrnam) self.noded_uid = GetUid(constants.NODED_USER, _getpwnam) self.noded_gid = GetGid(constants.NODED_GROUP, _getgrnam) self.mond_uid = GetUid(constants.MOND_USER, _getpwnam) self.mond_gid = GetGid(constants.MOND_GROUP, _getgrnam) self.metad_uid = GetUid(constants.METAD_USER, _getpwnam) self.metad_gid = GetGid(constants.METAD_GROUP, _getgrnam) # Misc Ganeti groups self.daemons_gid = GetGid(constants.DAEMONS_GROUP, _getgrnam) self.admin_gid = GetGid(constants.ADMIN_GROUP, _getgrnam) self._uid2user = { self.masterd_uid: constants.MASTERD_USER, self.confd_uid: constants.CONFD_USER, self.wconfd_uid: constants.WCONFD_USER, self.luxid_uid: constants.LUXID_USER, self.rapi_uid: constants.RAPI_USER, self.noded_uid: constants.NODED_USER, self.metad_uid: constants.METAD_USER, self.mond_uid: constants.MOND_USER, } self._gid2group = { self.masterd_gid: constants.MASTERD_GROUP, self.confd_gid: constants.CONFD_GROUP, self.wconfd_gid: constants.WCONFD_GROUP, self.luxid_gid: constants.LUXID_GROUP, self.rapi_gid: constants.RAPI_GROUP, self.noded_gid: constants.NODED_GROUP, self.mond_gid: constants.MOND_GROUP, self.metad_gid: constants.METAD_GROUP, self.daemons_gid: constants.DAEMONS_GROUP, self.admin_gid: constants.ADMIN_GROUP, } self._user2uid = utils.InvertDict(self._uid2user) self._group2gid = utils.InvertDict(self._gid2group)
from ganeti import constants from ganeti import objects from ganeti import pathutils from ganeti import hypervisor from ganeti import utils from ganeti import errors from ganeti import compat from ganeti.hypervisor import hv_base from ganeti.hypervisor import hv_xen import testutils # Map from hypervisor class to hypervisor name HVCLASS_TO_HVNAME = utils.InvertDict(hypervisor._HYPERVISOR_MAP) class TestConsole(unittest.TestCase): def test(self): hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL} for cls in [hv_xen.XenPvmHypervisor(), hv_xen.XenHvmHypervisor()]: instance = objects.Instance(name="xen.example.com", primary_node="node24828-uuid") node = objects.Node(name="node24828", uuid="node24828-uuid", ndparams={}) group = objects.NodeGroup(name="group52341", ndparams={}) cons = cls.GetInstanceConsole(instance, node, group, hvparams, {}) self.assertEqual(cons.Validate(), None) self.assertEqual(cons.kind, constants.CONS_SSH)