def test_get_hosts(self):
        hosts = rpc_interface.get_hosts()
        self._check_hostnames(hosts, [host.hostname for host in self.hosts])

        hosts = rpc_interface.get_hosts(hostname='host1')
        self._check_hostnames(hosts, ['host1'])
        host = hosts[0]
        self.assertEquals(sorted(host['labels']), ['label1', 'myplatform'])
        self.assertEquals(host['platform'], 'myplatform')
        self.assertEquals(host['atomic_group'], None)
        self.assertEquals(host['acls'], ['my_acl'])
        self.assertEquals(host['attributes'], {})
    def test_get_hosts_exclude_both(self):
        self.hosts[0].labels.add(self.label3)

        hosts = rpc_interface.get_hosts(
            hostname__in=['host1', 'host2', 'host5'],
            exclude_only_if_needed_labels=True,
            exclude_atomic_group_hosts=True)
        self._check_hostnames(hosts, ['host2'])
    def test_view_invalid_host(self):
        # RPCs used by View Host page should work for invalid hosts
        self._create_job_helper(hosts=[1], profiles=['N/A'])
        self.hosts[0].delete()

        self.assertEquals(1, rpc_interface.get_num_hosts(hostname='host1',
                                                         valid_only=False))
        data = rpc_interface.get_hosts(hostname='host1', valid_only=False)
        self.assertEquals(1, len(data))

        self.assertEquals(1, rpc_interface.get_num_host_queue_entries(
            host__hostname='host1'))
        data = rpc_interface.get_host_queue_entries(host__hostname='host1')
        self.assertEquals(1, len(data))

        count = rpc_interface.get_num_host_queue_entries_and_special_tasks(
            hostname='host1')
        self.assertEquals(1, count)
        data = rpc_interface.get_host_queue_entries_and_special_tasks(
            hostname='host1')
        self.assertEquals(1, len(data))
 def test_get_hosts_exclude_atomic_group_hosts(self):
     hosts = rpc_interface.get_hosts(
         exclude_atomic_group_hosts=True,
         hostname__in=['host4', 'host5', 'host6'])
     self._check_hostnames(hosts, ['host4'])
 def test_get_hosts_multiple_labels(self):
     hosts = rpc_interface.get_hosts(
         multiple_labels=['myplatform', 'label1'])
     self._check_hostnames(hosts, ['host1'])