Ejemplo n.º 1
0
    def test_w_interfaces_configured_in_both_groups_same_net(self):
        self.group.set_net_to_if('eth0', self.network11.name)
        self.new_group1.set_net_to_if('eth0', self.network11.name)

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)

        self.assertTrue(self.node.set_group(self.new_group1.name))

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)

        self.group = luna.Group(name=self.group.name, mongo_db=self.db)

        self.new_group1 = luna.Group(name=self.new_group1.name,
                                     mongo_db=self.db)

        self.network11 = luna.Network(name=self.network11.name,
                                      mongo_db=self.db)

        group_if_uid = None

        for uuid in self.new_group1._json['interfaces']:
            group_if_uid = uuid

        self.assertEqual(self.node._json['interfaces'][group_if_uid], {
            '4': 1,
            '6': None
        })

        self.assertEqual(self.network11._json['freelist'], [{
            'start': 2,
            'end': 65533
        }])
Ejemplo n.º 2
0
    def test_wo_interfaces_configured(self):

        self.assertTrue(self.node.set_group(self.new_group1.name))

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)

        self.group = luna.Group(name=self.group.name, mongo_db=self.db)

        self.new_group1 = luna.Group(name=self.new_group1.name,
                                     mongo_db=self.db)

        self.assertEqual(self.node._json['group'], self.new_group1.DBRef)

        self.assertEqual(self.node._json['_use_']['group'],
                         {str(self.new_group1._id): 1})

        group_if_uid = None

        for uuid in self.new_group1._json['interfaces']:
            group_if_uid = uuid

        self.assertEqual(self.node._json['interfaces'][group_if_uid], {
            '4': None,
            '6': None
        })

        self.assertEqual(self.group._json['_usedby_'], {})
Ejemplo n.º 3
0
    def test_w_interfaces_configured_in_new_group_net6(self):
        self.node = luna.Node(name=self.node.name, mongo_db=self.db)
        self.new_group1.set_net_to_if('eth0', self.network61.name)

        self.assertTrue(self.node.set_group(self.new_group1.name))

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)

        self.group = luna.Group(name=self.group.name, mongo_db=self.db)

        self.new_group1 = luna.Group(name=self.new_group1.name,
                                     mongo_db=self.db)

        self.network61 = luna.Network(name=self.network61.name,
                                      mongo_db=self.db)

        group_if_uid = None

        for uuid in self.new_group1._json['interfaces']:
            group_if_uid = uuid

        self.assertEqual(self.node._json['interfaces'][group_if_uid], {
            '4': None,
            '6': 1
        })

        self.assertEqual(self.network61._json['freelist'],
                         [{
                             'start': 2,
                             'end': 18446744073709551613
                         }])
Ejemplo n.º 4
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.group = luna.Group(name='testgroup',
                                osimage=self.osimage.name,
                                mongo_db=self.db,
                                interfaces=['eth0'],
                                create=True)

        self.new_group1 = luna.Group(name='new1',
                                     osimage=self.osimage.name,
                                     mongo_db=self.db,
                                     interfaces=['eth0'],
                                     create=True)

        self.node = luna.Node(group=self.group.name,
                              mongo_db=self.db,
                              create=True)

        self.network11 = luna.Network(name="net11",
                                      mongo_db=self.db,
                                      create=True,
                                      NETWORK='10.51.0.0',
                                      PREFIX=16)

        self.network61 = luna.Network(name="net61",
                                      mongo_db=self.db,
                                      create=True,
                                      NETWORK='fe80::',
                                      PREFIX=64,
                                      version=6)
Ejemplo n.º 5
0
    def test_same_ifs_different_nets(self):

        self.new_group2 = luna.Group(name='new2',
                                     osimage=self.osimage.name,
                                     mongo_db=self.db,
                                     interfaces=['eth0'],
                                     create=True)

        self.network12 = luna.Network(name="net12",
                                      mongo_db=self.db,
                                      create=True,
                                      NETWORK='10.52.0.0',
                                      PREFIX=16)

        self.group.set_net_to_if('eth0', self.network11.name)
        self.new_group2.set_net_to_if('eth0', self.network12.name)

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)
        self.node.set_ip(interface_name='eth0', ip='10.51.0.2')

        self.assertTrue(self.node.set_group(self.new_group2.name))

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)

        self.group = luna.Group(name=self.group.name, mongo_db=self.db)

        self.new_group2 = luna.Group(name=self.new_group2.name,
                                     mongo_db=self.db)

        self.network11 = luna.Network(name=self.network11.name,
                                      mongo_db=self.db)

        self.network12 = luna.Network(name=self.network12.name,
                                      mongo_db=self.db)

        group_if_uid = None

        for uuid in self.new_group2._json['interfaces']:
            group_if_uid = uuid

        self.assertEqual(self.node._json['interfaces'][group_if_uid], {
            '4': 1,
            '6': None
        })

        self.assertEqual(self.network11._json['freelist'], [{
            'start': 1,
            'end': 65533
        }])

        self.assertEqual(self.network12._json['freelist'], [{
            'start': 2,
            'end': 65533
        }])
Ejemplo n.º 6
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        print

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())
        self.cluster.set('path', self.path)

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.group = luna.Group(
            name='testgroup',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth0'],
            create=True,
        )

        self.group_new = luna.Group(
            name='testgroup_new',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth0'],
            create=True,
        )

        self.node = luna.Node(
            group=self.group.name,
            mongo_db=self.db,
            create=True,
        )
Ejemplo n.º 7
0
    def luna_inventory(self):
        osimage_suffix = ".osimages.luna"
        group_suffix = ".groups.luna"
        inventory = {}
        inventory['_meta'] = { 'hostvars': {}}
        osimages = {'hosts':[],'vars': {'ansible_connection': 'lchroot' }}
        for osimage in luna.list('osimage'):
            #osimages['hosts'].append(luna.OsImage(osimage).get('path'))
            osimages['hosts'].append(osimage + osimage_suffix)
            osimage_path = luna.OsImage(osimage).get('path')
            inventory['_meta']['hostvars'][osimage + osimage_suffix]= {
                'ansible_host': osimage,
            }

        inventory['osimages.luna'] = osimages

        nodes = {}
        inventory['groups.luna'] = {'hosts': []}

        for g in luna.list('group'):
            group = luna.Group(g)
            hosts = []
            nodes = group.list_nodes()

            for node_name in nodes:
                node = luna.Node(node_name)
                hosts.append(node_name)
                inventory['_meta']['hostvars'][node.show()['name']]={
                    "bmc_ip":node.get_ip('BMC',version=4)}

            inventory[g + group_suffix] = {'hosts': hosts}
            inventory['groups.luna']['hosts'].extend(hosts)

        return inventory
Ejemplo n.º 8
0
    def test_add_net_group_net4_node_net6(self):
        if self.sandbox.dbtype != 'mongo':
            raise unittest.SkipTest(
                'This test can be run only with MondoDB as a backend.')

        self.node.delete()
        self.group = luna.Group(name=self.group.name, mongo_db=self.db)
        self.group.set_net_to_if('eth0', self.network.name)
        self.node = luna.Node(
            group=self.group.name,
            mongo_db=self.db,
            create=True,
        )

        for key in self.node._json['interfaces']:

            if_dict = self.node._json['interfaces'][key]
            self.assertEqual(if_dict, {'4': 1, '6': None})

        self.group.set_net_to_if('eth0', self.network6.name)

        self.node = luna.Node(name=self.node.name, mongo_db=self.db)

        for key in self.node._json['interfaces']:

            if_dict = self.node._json['interfaces'][key]
            self.assertEqual(if_dict, {'4': 1, '6': 1})
Ejemplo n.º 9
0
def luna_group_absent(data):
    name = data['name']
    try:
        group = luna.Group(name=name)
    except RuntimeError:
        return False, False, name

    return not group.delete(), True, name
Ejemplo n.º 10
0
    def test_wo_nodes(self):
        if self.sandbox.dbtype != 'mongo':
            raise unittest.SkipTest(
                'This test can be run only with MongoDB as a backend.')

        self.group.set_net_to_if('eth0', self.network.name)
        self.node.delete()
        self.group = luna.Group(name=self.group.name, mongo_db=self.db)
        self.assertEqual(self.group.get_macs(self.network), {})
Ejemplo n.º 11
0
    def test_delete_group(self):
        if self.sandbox.dbtype != 'mongo':
            raise unittest.SkipTest(
                'This test can be run only with MondoDB as a backend.')

        group = luna.Group(name='testgroup',
                           osimage=str(self.osimage.name),
                           mongo_db=self.db,
                           interfaces=['eth0'],
                           create=True)
        groupid = group._id
        group.delete()

        doc = self.db['group'].find_one({'_id': groupid})
        self.assertIsNone(doc)
Ejemplo n.º 12
0
    def test_create_group_with_defaults(self):

        group = luna.Group(name='testgroup1',
                           osimage=str(self.osimage.name),
                           mongo_db=self.db,
                           interfaces=['BOOTIF'],
                           create=True)

        doc = self.db['group'].find_one({'_id': group._id})
        expected = {
            'torrent_if':
            None,
            'partscript':
            'mount -t tmpfs tmpfs /sysroot',
            'postscript':
            ('cat << EOF >> /sysroot/etc/fstab\n' +
             'tmpfs   /       tmpfs    defaults        0 0\n' + 'EOF'),
            'name':
            'testgroup1',
            'bmcsetup':
            None,
            'domain':
            None,
            '_use_': {
                'cluster': {
                    str(self.cluster._id): 1
                },
                'osimage': {
                    str(self.osimage._id): 1
                }
            },
            'osimage':
            self.osimage.DBRef,
            'comment':
            ''
        }

        for attr in expected:
            self.assertEqual(doc[attr], expected[attr])
        # check interfaces
        if_dict = doc['interfaces']
        self.assertEqual(len(if_dict), 1)
        for uuid in if_dict:
            self.assertEqual(if_dict[uuid]['name'], 'BOOTIF')
            self.assertEqual(if_dict[uuid]['params'], '')
            self.assertEqual(if_dict[uuid]['network'], {'4': None, '6': None})
Ejemplo n.º 13
0
    def test_create_node_exhausted_ips(self):
        net = luna.Network(
            'net',
            mongo_db=self.db,
            create=True,
            NETWORK='10.50.0.0',
            PREFIX=16,
        )

        tight_net = luna.Network(
            'tight_net',
            mongo_db=self.db,
            create=True,
            NETWORK='10.51.0.0',
            PREFIX=30,
        )

        self.group.add_interface('eth1')

        self.group.set_net_to_if('eth0', net.name)
        self.group.set_net_to_if('eth1', tight_net.name)

        node = luna.Node(
            group=self.group.name,
            mongo_db=self.db,
            create=True,
        )

        with self.assertRaises(RuntimeError):
            luna.Node(
                group=self.group.name,
                mongo_db=self.db,
                create=True,
            )
        tight_net = luna.Network(name=tight_net.name, mongo_db=self.db)

        net = luna.Network(name=net.name, mongo_db=self.db)

        self.group = luna.Group(name=self.group.name, mongo_db=self.db)

        self.assertEqual(tight_net._json['freelist'], [])
        self.assertEqual(net._json['freelist'], [{'start': 2, 'end': 65533}])
        self.assertEqual(len(self.group._json['_usedby_']['node']), 1)
Ejemplo n.º 14
0
def luna_group_present(data):
    data.pop('state')
    name = data.pop('name')

    # perform interface data checking, make sure networks are exist,
    # interface names are unique, etc.
    #
    interfaces = data.pop('interfaces')
    tmp_interfaces = {}
    for elem in interfaces:

        if not 'name' in elem:
            return True, False, "No name for interface defined"

        if_name = elem['name']

        if if_name in tmp_interfaces.keys():
            err_msg = "Duplicate name for interface '{}'".format(if_name)
            return True, False, err_msg

        tmp_interfaces[if_name] = {}

        if 'params' in elem:
            tmp_interfaces[if_name]['params'] = elem['params']
        else:
            tmp_interfaces[if_name]['params'] = None

        nets = {'4': None, '6': None}

        if not 'networks' in elem:
            tmp_interfaces[if_name]['networks'] = nets
            continue

        for network in elem['networks']:
            try:
                net = luna.Network(name=network)
            except RuntimeError:
                err_msg = "No such network '{}'".format(network)
                return True, False, err_msg

            if net.version in nets:
                err_msg = "The can be only one v4 and one v6 network"
                return True, False, err_msg

            nets[str(net.version)] = net.name

        tmp_interfaces[if_name]['networks'] = nets

    data['interfaces'] = tmp_interfaces

    changed = False
    ret = True

    try:
        group = luna.Group(name=name)

    except RuntimeError:
        args = data.copy()

        if args['osimage'] is None:
            err_msg = "OsImage should be specified"
            return True, False, err_msg

        args['name'] = name
        args['create'] = True
        args['interfaces'] = data['interfaces'].keys()
        group = luna.Group(**args)
        changed = True

    keys = ['prescript', 'postscript', 'partscript', 'torrent_if', 'comment']
    group_show = group.show()

    for key in keys:
        if data[key] is None:
            continue
        if group_show[key] != data[key]:
            ret &= group.set(key, data[key])
            changed = True

    # FIXME
    # need to change API in luna
    if (data['domain'] is not None
            and group_show['domain'] != '[' + data['domain'] + ']'):
        ret &= group.set_domain(data['domain'])
        changed = True

    if (data['bmcsetup'] is not None
            and group_show['bmcsetup'] != '[' + data['bmcsetup'] + ']'):
        ret &= group.bmcsetup(data['bmcsetup'])
        changed = True

    if (data['osimage'] is not None
            and group_show['osimage'] != '[' + data['osimage'] + ']'):
        ret &= group.osimage(data['osimage'])
        changed = True

    # make sure sets of the interfaces are the same
    ansible_ifs = set(data['interfaces'].keys())
    configured_ifs = set(group.list_ifs().keys())

    ifs_to_delete = [e for e in configured_ifs if e not in ansible_ifs]
    ifs_to_add = [e for e in ansible_ifs if e not in configured_ifs]

    for interface in ifs_to_delete:
        changed = True
        ret &= group.del_interface(interface)

    for interface in ifs_to_add:
        changed = True
        ret &= group.add_interface(interface)

    # now make sure we have same nets assigned
    for interface in ansible_ifs:
        if_json = group.show_if(interface)
        if_params = data['interfaces'][interface]['params']

        if (if_params is not None
                and if_params != group.get_if_params(interface)):
            ret &= group.set_if_params(interface, if_params)
            changed = True

        for net_ver in ['4', '6']:
            ansible_net = data['interfaces'][interface]['networks'][net_ver]
            configured_net = if_json['network'][net_ver]['name'] or None

            if ansible_net == configured_net:
                continue

            if ansible_net is None:
                group.del_net_from_if(interface, configured_net)
                changed = True
            else:
                if configured_net is not None:
                    ret &= group.del_net_from_if(interface, configured_net)
                ret &= group.set_net_to_if(interface, ansible_net)
                changed = True

    return not ret, changed, ""
Ejemplo n.º 15
0
import luna
#group = luna.Group(create = True, name = 'compute1', osimage = 'compute1', bmcsetup = 'base', bmcnetwork = 'internal')
#group = luna.Group(create = True, name = 'compute2', osimage = 'compute1', bmcsetup = 'base', bmcnetwork = 'internal', interfaces = ['eth0'])
group = luna.Group('compute2')
group.add_interface('eht1')
group.set_net_to_if('eht1', 'internal')
group.del_net_from_if('eht1')
group.del_interface('eht1')
group.set_if_parms('eth0', 'BOOTPROTO=none\nONBOOT=yes')
print group.get_if_parms('eth0')
Ejemplo n.º 16
0
    def _get_nodes(self, group=None, nodelist=None):
        def transform_node_dict(nodes, node):
            node_dict = nodes[node]
            ret_dict = {'node': node, 'BOOTIF': '', 'BMC': ''}
            if 'interfaces' in node_dict:
                if 'BOOTIF' in node_dict['interfaces']:
                    ret_dict['BOOTIF'] = node_dict['interfaces']['BOOTIF'][4]
                if 'BMC' in node_dict['interfaces']:
                    ret_dict['BMC'] = node_dict['interfaces']['BMC'][4]

            return ret_dict

        if not luna_present:
            log.error("Luna 1.2 is not installed")
            return []
        nodes = []
        av_groups = luna.list('group')
        if group is None:
            groups = av_groups
        else:
            if group not in av_groups:
                self.log.error("No such group '{}'".format(group))
                return []
            groups = [group]

        for group_name in groups:
            group = luna.Group(group_name)
            domain = group.boot_params['domain']
            group_nodes = group.list_nodes()
            sorted_keys = group_nodes.keys()
            sorted_keys.sort()
            ipmi_username = ''
            ipmi_password = ''

            if 'bmcsetup' in group.install_params:
                bmcsetup = group.install_params['bmcsetup']
                if 'user' in bmcsetup:
                    ipmi_username = bmcsetup['user']
                if 'password' in bmcsetup:
                    ipmi_password = bmcsetup['password']

            for node_name in sorted_keys:
                node_dict = transform_node_dict(group_nodes, node_name)
                node_dict['ipmi_username'] = ipmi_username
                node_dict['ipmi_password'] = ipmi_password
                node_dict['hostname'] = node_name
                if domain:
                    node_dict['hostname'] += "." + domain
                nodes.append(node_dict)

        if not nodelist:
            return nodes

        nodelist = ",".join(nodelist)

        if not hostlist_present:
            self.log.info(
                "hostlist is not installed. List of nodes will not be expanded"
            )
            nodelist = nodelist.split(",")
        else:
            nodelist = hostlist.expand_hostlist(nodelist)

        return filter(lambda x: x['node'] in nodelist, nodes)
Ejemplo n.º 17
0
    def test_creation_group(self):
        bmcsetup = luna.BMCSetup(name='bmcsetup',
                                 mongo_db=self.db,
                                 create=True)
        net = luna.Network(name='cluster',
                           NETWORK='10.11.0.0',
                           PREFIX=16,
                           mongo_db=self.db,
                           create=True)
        nics = ['eth0', 'eth1']
        group = luna.Group(name='testgroup2',
                           osimage=self.osimage.name,
                           bmcsetup=bmcsetup.name,
                           mongo_db=self.db,
                           interfaces=nics,
                           domain=net.name,
                           torrent_if=nics[1],
                           create=True)

        doc = self.db['group'].find_one({'_id': group._id})
        expected = {
            'torrent_if':
            nics[1],
            'partscript':
            'mount -t tmpfs tmpfs /sysroot',
            'postscript':
            ('cat << EOF >> /sysroot/etc/fstab\n' +
             'tmpfs   /       tmpfs    defaults        0 0\n' + 'EOF'),
            'name':
            'testgroup2',
            'bmcsetup':
            bmcsetup.DBRef,
            'domain':
            net.DBRef,
            '_use_': {
                'cluster': {
                    str(self.cluster._id): 1
                },
                'osimage': {
                    str(self.osimage._id): 1
                },
                'network': {
                    str(net._id): 1,
                },
                'bmcsetup': {
                    str(bmcsetup._id): 1
                },
            },
            'osimage':
            self.osimage.DBRef,
            'comment':
            '',
        }

        for attr in expected:
            self.assertEqual(doc[attr], expected[attr])
        # check interfaces
        if_dict = doc['interfaces']
        self.assertEqual(len(if_dict), len(nics))
        for uuid in if_dict:
            self.assertIn(if_dict[uuid]['name'], nics)
            self.assertEqual(if_dict[uuid]['params'], '')
            self.assertEqual(if_dict[uuid]['network'], {'4': None, '6': None})
            nics.remove(if_dict[uuid]['name'])
Ejemplo n.º 18
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path
        #osimage_path = self.sandbox.create_osimage()

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())

        self.cluster.set("frontend_address", "127.0.0.1")

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.bmcsetup = luna.BMCSetup(name='bmcsetup',
                                      mongo_db=self.db,
                                      create=True)

        self.net1 = luna.Network(name='cluster',
                                 NETWORK='10.11.0.0',
                                 PREFIX=16,
                                 mongo_db=self.db,
                                 create=True)
        self.net2 = luna.Network(name='external',
                                 NETWORK='10.12.0.0',
                                 PREFIX=16,
                                 mongo_db=self.db,
                                 create=True)
        self.net3 = luna.Network(name='ib',
                                 NETWORK='10.13.0.0',
                                 PREFIX=16,
                                 mongo_db=self.db,
                                 create=True)

        self.net6 = luna.Network(name='net6',
                                 NETWORK='fe80::',
                                 PREFIX=64,
                                 mongo_db=self.db,
                                 create=True,
                                 version=6)

        self.prescript = 'pre'
        self.postscript = 'post'
        self.partscript = 'part'
        self.nics = {'eth0': 'PARM=1', 'eth1': 'PARM=2', 'ib0': 'PARM=3'}

        self.group = luna.Group(name='compute',
                                osimage=self.osimage.name,
                                mongo_db=self.db,
                                interfaces=['eth0'],
                                create=True)
Ejemplo n.º 19
0
                    NETMASK='255.255.255.0')
ifcfg2 = luna.IfCfg(name='internal2',
                    create=True,
                    NETWORK='192.168.2.0',
                    PREFIX=24,
                    NETMASK='255.255.255.0')
ifcfg3 = luna.IfCfg(name='internal3',
                    create=True,
                    NETWORK='192.168.3.0',
                    PREFIX=24,
                    NETMASK='255.255.255.0')
ipmi = luna.IfCfg(name='ipmi', create=True, NETWORK='10.10.0.0', PREFIX=16)
bmc = luna.BMCSetup(name='base', create=True)
osimage = luna.OsImage(create=True,
                       name='compute1',
                       path='/os/compute-image',
                       kernver='3.10.0-327.3.1.el7.x86_64')
osimage = luna.OsImage(create=True,
                       name='compute2',
                       path='/os/compute-image-2',
                       kernver='3.10.0-327.3.1.el7.x86_64')
group = luna.Group(create=True,
                   name='compute-group',
                   bmcsetup='base',
                   bmcnetwork='ipmi',
                   osimage='compute1',
                   interfaces={
                       'eth0': 'internal1',
                       'eth1': 'internal2'
                   })
Ejemplo n.º 20
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_addmacro.return_value = True
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())
        self.cluster.set('path', self.path)
        self.cluster.set('frontend_address', '127.0.0.1')

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.net1 = luna.Network(
            'testnet1',
            mongo_db=self.db,
            create=True,
            NETWORK='10.50.0.0',
            PREFIX=16,
        )

        self.net2 = luna.Network(
            'testnet2',
            mongo_db=self.db,
            create=True,
            NETWORK='10.51.0.0',
            PREFIX=16,
        )

        self.group = luna.Group(
            name='testgroup',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth0'],
            create=True,
        )

        self.group_new = luna.Group(
            name='testgroup_new',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth0'],
            create=True,
        )

        self.node = luna.Node(
            group=self.group.name,
            mongo_db=self.db,
            create=True,
        )

        self.boot_expected_dict = {
            'domain': '',
            'initrd_file': '',
            'mac': '',
            'kernel_file': '',
            'localboot': 0,
            'name': 'node001',
            'service': 0,
            'net': {},
            'hostname': 'node001',
            'kern_opts': '',
            'bootproto': 'dhcp'
        }

        self.install_expected_dict = {
            'torrent_if':
            '',
            'setupbmc':
            True,
            'partscript':
            'mount -t tmpfs tmpfs /sysroot',
            'name':
            'node001',
            'tarball':
            '',
            'bmcsetup': {},
            'interfaces': {
                'BOOTIF': {
                    'options': '',
                    '4': {
                        'ip': '',
                        'netmask': '',
                        'prefix': '',
                    },
                    '6': {
                        'ip': '',
                        'netmask': '',
                        'prefix': '',
                    }
                },
                'eth0': {
                    'options': '',
                    '4': {
                        'ip': '',
                        'netmask': '',
                        'prefix': '',
                    },
                    '6': {
                        'ip': '',
                        'netmask': '',
                        'prefix': '',
                    }
                }
            },
            'prescript':
            '',
            'domain':
            '',
            'hostname':
            'node001',
            'postscript':
            ('cat << EOF >> /sysroot/etc/fstab\n' +
             'tmpfs   /       tmpfs    defaults        0 0\n' + 'EOF'),
            'kernopts':
            '',
            'kernver':
            '3.10-999-el0.x86_64',
            'torrent':
            '',
            'mac':
            '',
        }
Ejemplo n.º 21
0
    def test_node_change_group(self):

        # create 3 groups

        group1 = self.group

        group2 = luna.Group(
            name='testgroup2',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth0'],
            create=True,
        )

        group3 = luna.Group(
            name='testgroup3',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth1'],
            create=True,
        )

        group4 = luna.Group(
            name='testgroup4',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth3'],
            create=True,
        )

        # create 3 networks

        net1 = luna.Network(
            'testnet1',
            mongo_db=self.db,
            create=True,
            NETWORK='10.50.0.0',
            PREFIX=16,
        )

        net2 = luna.Network(
            'testnet2',
            mongo_db=self.db,
            create=True,
            NETWORK='10.51.0.0',
            PREFIX=16,
        )

        net3 = luna.Network(
            'testnet3',
            mongo_db=self.db,
            create=True,
            NETWORK='10.52.0.0',
            PREFIX=16,
        )

        # assign 2 networks to interfaces
        # group1: {'eth0': net1}
        # group2  {'eth0': net1, 'em1':  net2}
        # group3  {'em1':  net1, 'eth1': net2}
        # group4  {'eth3': net3}

        group2.add_interface('em1')
        group3.add_interface('em1')

        group1.set_net_to_if('eth0', net1.name)
        group2.set_net_to_if('eth0', net1.name)
        group3.set_net_to_if('eth1', net2.name)
        group4.set_net_to_if('eth3', net3.name)

        group2.set_net_to_if('em1', net2.name)
        group3.set_net_to_if('em1', net1.name)

        self.node = luna.Node(
            name=self.node.name,
            mongo_db=self.db,
        )

        # create 9 more nodes

        nodes = []
        for i in range(10):
            nodes.append(
                luna.Node(
                    group=self.group,
                    create=True,
                    mongo_db=self.db,
                ))

        # will do tests with node005

        node005 = luna.Node('node005', mongo_db=self.db, group=self.group)

        # check did we get desired config
        node_json = self.db['node'].find_one({'name': node005.name})
        net1_json = self.db['network'].find_one({'name': net1.name})

        self.assertEqual(node_json['group'], group1.DBRef)
        for k in node_json['interfaces']:
            self.assertEqual(node_json['interfaces'][k], {'4': 5, '6': None})
        self.assertEqual(len(net1_json['freelist']), 1)
        self.assertEqual(net1_json['freelist'][0]['start'], 12)
        #node_json['interfaces'], net1_json['freelist']

        #
        # change group first time:
        #
        self.assertEqual(node005.set_group(group2.name), True)
        # updating group objects
        group1 = luna.Group(
            name=group1.name,
            mongo_db=self.db,
        )
        group2 = luna.Group(
            name=group2.name,
            mongo_db=self.db,
        )

        node_json = self.db['node'].find_one({'name': node005.name})
        group2_json = self.db['group'].find_one({'name': group2.name})
        net1_json = self.db['network'].find_one({'name': net1.name})
        net2_json = self.db['network'].find_one({'name': net2.name})

        # should be 2 interfaces now
        self.assertEqual(len(node_json['interfaces']), 2)
        #  those interfaces should be the ones from group2
        for uid in node_json['interfaces']:
            self.assertIn(uid, group2_json['interfaces'].keys())
        # check if eth0 has the same IP adress:
        eth0_uuid = ''
        em1_uuid = ''
        for if_uid in group2_json['interfaces']:
            if group2_json['interfaces'][if_uid]['name'] == 'eth0':
                eth0_uuid = if_uid
            if group2_json['interfaces'][if_uid]['name'] == 'em1':
                em1_uuid = if_uid
        # check if we found
        self.assertIsNot(eth0_uuid, '')
        self.assertIsNot(em1_uuid, '')
        # should be 5
        self.assertEqual(node_json['interfaces'][eth0_uuid], {
            '4': 5,
            '6': None
        })
        # another should be 1
        self.assertEqual(node_json['interfaces'][em1_uuid], {
            '4': 1,
            '6': None
        })

        # check network
        self.assertEqual(net1_json['freelist'], [{'start': 12, 'end': 65533}])
        self.assertEqual(net2_json['freelist'], [{'start': 2, 'end': 65533}])

        #
        # change group second time
        #
        self.assertEqual(node005.set_group(group3.name), True)
        # fetch the data from DB
        node_json = self.db['node'].find_one({'name': node005.name})
        group3_json = self.db['group'].find_one({'name': group3.name})
        net1_json = self.db['network'].find_one({'name': net1.name})
        net2_json = self.db['network'].find_one({'name': net2.name})
        # try to find uuids of the interfaces
        eth1_uuid = ''
        em1_uuid = ''
        for if_uid in group3_json['interfaces']:
            if group3_json['interfaces'][if_uid]['name'] == 'eth1':
                eth1_uuid = if_uid
            if group3_json['interfaces'][if_uid]['name'] == 'em1':
                em1_uuid = if_uid
        # check if we found
        self.assertIsNot(eth1_uuid, '')
        self.assertIsNot(em1_uuid, '')
        # should be 1
        self.assertEqual(node_json['interfaces'][eth1_uuid], {
            '4': 1,
            '6': None
        })
        # another should be 5
        self.assertEqual(node_json['interfaces'][em1_uuid], {
            '4': 5,
            '6': None
        })

        #
        # change group third time
        #
        self.assertEqual(node005.set_group(group4.name), True)
        node_json = self.db['node'].find_one({'name': node005.name})
        net1_json = self.db['network'].find_one({'name': net1.name})
        net2_json = self.db['network'].find_one({'name': net2.name})
        net3_json = self.db['network'].find_one({'name': net3.name})
        self.assertEqual(net1_json['freelist'], [{
            'start': 5,
            u'end': 5
        }, {
            'start': 12,
            'end': 65533
        }])
        self.assertEqual(net2_json['freelist'], [{'start': 1, 'end': 65533}])
        self.assertEqual(net3_json['freelist'], [{'start': 2, 'end': 65533}])
Ejemplo n.º 22
0
import luna

group = luna.Group('compute1')
#print group.install_params
node = luna.Node('node001')
print node.install_params
Ejemplo n.º 23
0
import luna
import pymongo

#client = pymongo.MongoClient()
#client.drop_database('luna')


#opt = luna.Options(create = True)
#ifcfg1 = luna.IfCfg(name = 'internal1', create=True, NETWORK = '192.168.1.0', PREFIX = 24, NETMASK = '255.255.255.0' )
#ifcfg2 = luna.IfCfg(name = 'internal2', create=True, NETWORK = '192.168.2.0', PREFIX = 24, NETMASK = '255.255.255.0' )
#ifcfg3 = luna.IfCfg(name = 'internal3', create=True, NETWORK = '192.168.3.0', PREFIX = 24, NETMASK = '255.255.255.0' )
#ipmi = luna.IfCfg(name = 'ipmi', create=True, NETWORK = '10.10.0.0', PREFIX = 16 )
#bmc = luna.BMCSetup(name = 'base', create = True)
#osimage = luna.OsImage(create=True, name='compute1', path='/os/compute-image', kernver='3.10.0-327.3.1.el7.x86_64')
#osimage = luna.OsImage(create=True, name='compute2', path='/os/compute-image-2', kernver='3.10.0-327.3.1.el7.x86_64')
group = luna.Group(name='compute-group')
print group.osimage('compute1')
print group.nice_json
print group.osimage('compute2')
print group.nice_json
Ejemplo n.º 24
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        if self.sandbox.dbtype != 'mongo':
            raise unittest.SkipTest(
                'This test can be run only with MongoDB as a backend.')

        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.group1 = luna.Group(name='testgroup1',
                                 osimage=self.osimage.name,
                                 mongo_db=self.db,
                                 interfaces=['eth0'],
                                 create=True)

        self.group2 = luna.Group(name='testgroup2',
                                 osimage=self.osimage.name,
                                 mongo_db=self.db,
                                 interfaces=['BOOTIF'],
                                 create=True)

        self.net11 = luna.Network(name='net11',
                                  NETWORK='10.11.0.0',
                                  PREFIX=16,
                                  mongo_db=self.db,
                                  create=True)

        self.group1.set_net_to_if('eth0', self.net11.name)
        self.group2.set_net_to_if('BOOTIF', self.net11.name)

        self.node1 = luna.Node(group=self.group1.name,
                               mongo_db=self.db,
                               create=True)

        self.node2 = luna.Node(group=self.group2.name,
                               mongo_db=self.db,
                               create=True)

        self.node1.set_mac('00:11:22:33:44:55')
        self.node2.set_mac('01:11:22:33:44:55')

        self.group1 = luna.Group(name=self.group1.name, mongo_db=self.db)
        self.group2 = luna.Group(name=self.group2.name, mongo_db=self.db)

        self.net11 = luna.Network(name=self.net11.name, mongo_db=self.db)
        self.node1 = luna.Node(name=self.node1.name, mongo_db=self.db)
        self.node2 = luna.Node(name=self.node2.name, mongo_db=self.db)
Ejemplo n.º 25
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.group = luna.Group(name='testgroup',
                                osimage=self.osimage.name,
                                mongo_db=self.db,
                                interfaces=['eth0'],
                                create=True)

        self.net11 = luna.Network(name='net11',
                                  NETWORK='10.11.0.0',
                                  PREFIX=16,
                                  mongo_db=self.db,
                                  create=True)
        self.net11.set('ns_hostname', 'master')

        self.net61 = luna.Network(name='net61',
                                  NETWORK='fe90::',
                                  PREFIX=64,
                                  mongo_db=self.db,
                                  create=True)
        self.net61.set('ns_hostname', 'master')

        self.group.set_net_to_if('eth0', self.net11.name)
        self.group.set_net_to_if('eth0', self.net61.name)

        self.group = luna.Group(name=self.group.name, mongo_db=self.db)

        self.node = luna.Node(group=self.group.name,
                              mongo_db=self.db,
                              create=True)

        self.switch = luna.Switch(name='sw01',
                                  network=self.net11.name,
                                  mongo_db=self.db,
                                  create=True)
        self.switch.set('ip', '10.11.1.1')

        self.otherdev = luna.OtherDev(name='pdu01',
                                      network=self.net11.name,
                                      ip="10.11.2.1",
                                      mongo_db=self.db,
                                      create=True)

        self.net11 = luna.Network(name=self.net11.name, mongo_db=self.db)
        self.node = luna.Node(name=self.node.name, mongo_db=self.db)
        self.group = luna.Group(name=self.group.name, mongo_db=self.db)
Ejemplo n.º 26
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())

        self.cluster.set("frontend_address", "127.0.0.1")

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.bmcsetup = luna.BMCSetup(name='bmcsetup',
                                      mongo_db=self.db,
                                      create=True)

        self.net1 = luna.Network(name='cluster',
                                 NETWORK='10.11.0.0',
                                 PREFIX=16,
                                 mongo_db=self.db,
                                 create=True)
        self.net2 = luna.Network(name='external',
                                 NETWORK='10.12.0.0',
                                 PREFIX=16,
                                 mongo_db=self.db,
                                 create=True)
        self.net3 = luna.Network(name='ib',
                                 NETWORK='10.13.0.0',
                                 PREFIX=16,
                                 mongo_db=self.db,
                                 create=True)

        self.prescript = 'pre'
        self.postscript = 'post'
        self.partscript = 'part'
        self.nics = {'BOOTIF': 'PARM=1', 'eth1': 'PARM=2', 'ib0': 'PARM=3'}

        self.group = luna.Group(name='compute',
                                osimage=self.osimage.name,
                                mongo_db=self.db,
                                interfaces=['BOOTIF'],
                                create=True)

        # mocking osimage boot stuff
        with mock.patch('os.path'), \
                mock.patch('shutil.copy'), \
                mock.patch('os.remove'), \
                mock.patch('os.chown'), \
                mock.patch('os.chmod'), \
                mock.patch('subprocess.Popen') as mock_subprocess_popen, \
                mock.patch('os.open'), \
                mock.patch('os.chroot'), \
                mock.patch('os.fchdir'), \
                mock.patch('os.close'), \
                mock.patch('os.chdir'), \
                mock.patch('shutil.move'), \
                mock.patch('libtorrent.add_files'), \
                mock.patch('libtorrent.set_piece_hashes'):

            (mock_subprocess_popen.return_value.stderr.readline.return_value
             ) = ''

            self.osimage.copy_boot()
            self.osimage.create_tarball()
            self.osimage.create_torrent()

        group_json = self.db['group'].find_one({'_id': self.group._id})
        osimage_json = self.db['osimage'].find_one({'_id': self.osimage._id})

        self.install_expected_dict = {
            'torrent_if': '',
            'partscript': group_json['partscript'],
            'tarball': osimage_json['tarball'] + '.tgz',
            'bmcsetup': {},
            'interfaces': {
                'BOOTIF': {
                    'options': '',
                    '4': {
                        'ip': '',
                        'netmask': '',
                        'prefix': '',
                    },
                    '6': {
                        'ip': '',
                        'netmask': '',
                        'prefix': '',
                    }
                }
            },
            'prescript': '',
            'domain': '',
            'postscript': group_json['postscript'],
            'kernopts': '',
            'kernver': '3.10-999-el0.x86_64',
            'torrent': osimage_json['torrent'] + '.torrent'
        }
Ejemplo n.º 27
0
import luna

node1 = luna.Node(group='compute-group', create=True)
print str(node1.show())
node = luna.Node('node015')
print str(node.show())

group = luna.Group('compute-group')
print str(group.show())
Ejemplo n.º 28
0
    def setUp(
        self,
        mock_rpm_addmacro,
        mock_rpm_transactionset,
    ):

        print

        packages = [
            {
                'VERSION': '3.10',
                'RELEASE': '999-el0',
                'ARCH': 'x86_64'
            },
        ]
        mock_rpm_transactionset.return_value.dbMatch.return_value = packages

        self.sandbox = Sandbox()
        self.db = self.sandbox.db
        self.path = self.sandbox.path

        self.cluster = luna.Cluster(mongo_db=self.db,
                                    create=True,
                                    path=self.path,
                                    user=getpass.getuser())
        self.cluster.set('path', self.path)
        self.cluster.set('frontend_address', '127.0.0.1')

        self.osimage = luna.OsImage(name='testosimage',
                                    path=self.path,
                                    mongo_db=self.db,
                                    create=True)

        self.net = luna.Network(
            'testnet',
            mongo_db=self.db,
            create=True,
            NETWORK='fe80::',
            PREFIX=64,
        )

        self.net.set('ns_hostname', 'master')

        self.group = luna.Group(
            name='testgroup',
            osimage=self.osimage.name,
            mongo_db=self.db,
            interfaces=['eth0'],
            create=True,
        )

        self.group.set_net_to_if('eth0', self.net.name)

        self.nodes = []
        for i in range(10):
            self.nodes.append(
                luna.Node(
                    group=self.group,
                    create=True,
                    mongo_db=self.db,
                ))

        self.net = luna.Network(name=self.net.name, mongo_db=self.db)