def _call(): with database.session() as session: cluster = model.Cluster(name='cluster1') cluster.hosts = [ model.ClusterHost(hostname='host1'), model.ClusterHost(hostname='host1') ] session.add(cluster)
def test_cluster_empty_name(self): with database.session() as session: session.add(model.Cluster(name='')) with database.session() as session: clusters = session.query(model.Cluster).all() self.assertEqual(len(clusters), 1) self.assertIsNotNone(clusters[0].name) self.assertFalse(clusters[0].name == '')
def test_hostname_empty(self): with database.session() as session: cluster = model.Cluster() cluster.hosts = [model.ClusterHost(hostname='')] session.add(cluster) with database.session() as session: hosts = session.query(model.ClusterHost).all() self.assertEqual(len(hosts), 1) self.assertIsNotNone(hosts[0].hostname) self.assertFalse(hosts[0].hostname == '')
def test_clusterhost_delete_cluster(self): with database.session() as session: cluster = model.Cluster(name='cluster1') cluster.hosts = [model.ClusterHost(hostname='host1')] session.add(cluster) with database.session() as session: session.query(model.Cluster).delete() with database.session() as session: host = session.query(model.ClusterHost).first() self.assertIsNone(host.cluster)
def test_cluster_adapter(self): with database.session() as session: adapter = model.Adapter(name='CentOS_openstack', os='CentOS', target_system='openstack') cluster = model.Cluster(name='cluster1') cluster.adapter = adapter session.add(cluster) with database.session() as session: adapter = session.query(model.Adapter).first() self.assertEqual(adapter.clusters.count(), 1)
def test_clusterhost(self): with database.session() as session: host = model.ClusterHost(hostname='host1') host.cluster = model.Cluster(name='cluster1') host.machine = model.Machine(mac='00:00:00:01:02:03', port='123', vlan=100) host.machine.switch = model.Switch(ip='192.168.1.1') session.add(host) with database.session() as session: host = session.query(model.ClusterHost).first() self.assertEqual(host.cluster.name, 'cluster1') self.assertEqual(host.machine.mac, '00:00:00:01:02:03') self.assertEqual(host.machine.switch.ip, '192.168.1.1')
def test_adapter_del(self): with database.session() as session: adapter = model.Adapter(name='CentOS_openstack', os='CentOS', target_system='openstack') cluster = model.Cluster(name='cluster1') cluster.adapter = adapter session.add(cluster) with database.session() as session: session.query(model.Adapter).delete() with database.session() as session: cluster = session.query(model.Cluster).first() self.assertIsNone(cluster.adapter)
def test_cluster_del(self): with database.session() as session: adapter = model.Adapter(name='CentOS_openstack', os='CentOS', target_system='openstack') cluster = model.Cluster(name='cluster1') cluster.adapter = adapter session.add(cluster) with database.session() as session: session.query(model.Cluster).delete() with database.session() as session: adapters = session.query(model.Adapter).all() self.assertEqual(len(adapters), 1)
def test_clusterhost_delete_host(self): with database.session() as session: cluster = model.Cluster(name='cluster1') host = model.ClusterHost(hostname='host1') cluster.hosts = [host] host.machine = model.Machine(mac='00:00:00:01:02:03', port='123', vlan=100) session.add(cluster) with database.session() as session: session.query(model.ClusterHost).delete() with database.session() as session: cluster = session.query(model.Cluster).first() self.assertEqual(cluster.hosts.count(), 0) machine = session.query(model.Machine).first() self.assertIsNone(machine.host)
def test_host_config(self): with database.session() as session: cluster = model.Cluster(name='cluster1') host = model.ClusterHost(hostname='host1') host.machine = model.Machine(mac='00:00:00:01:02:03', port='123', vlan=100) host.machine.switch = model.Switch(ip='192.168.1.1') cluster.hosts = [host] host.config = { 'networking': { 'interfaces': { 'management': { 'ip': '192.168.1.100' } } } } session.add(cluster) with database.session() as session: host = session.query(model.ClusterHost).first() self.assertDictContainsSubset( { 'hostname': 'host1', 'clustername': 'cluster1', 'networking': { 'interfaces': { 'management': { 'mac': '00:00:00:01:02:03', 'ip': '192.168.1.100' } } }, 'switch_port': '123', 'vlan': 100, 'switch_ip': '192.168.1.1' }, host.config)
def test_cluster_config_set(self): with database.session() as session: cluster = model.Cluster(name='cluster1') cluster.config = { 'security': { 'user': '******', 'password': '******' }, 'networking': { 'interface': 'eth0', }, 'partition': '/tmp 20%' } session.add(cluster) with database.session() as session: cluster = session.query(model.Cluster).first() self.assertEqual(cluster.security, { 'user': '******', 'password': '******' }) self.assertEqual(cluster.networking, {'interface': 'eth0'}) self.assertEqual(cluster.partition, '/tmp 20%')
def test_cluster_config(self): with database.session() as session: cluster = model.Cluster(name='cluster1') cluster.security = {'user': '******', 'password': '******'} cluster.networking = { 'interface': 'eth0', } cluster.partition = '/tmp 20%' session.add(cluster) with database.session() as session: cluster = session.query(model.Cluster).first() self.assertDictContainsSubset( { 'clustername': 'cluster1', 'security': { 'user': '******', 'password': '******' }, 'networking': { 'interface': 'eth0' }, 'partition': '/tmp 20%' }, cluster.config)
def _call(): with database.session() as session: session.add(model.Cluster(name='cluster1')) session.add(model.Cluster(name='cluster1'))