def test_host_labels_create(self): region_id = self.make_region('region_1', foo='R1') host_id = self.make_host(region_id, 'www.example.xyz', IPAddress(u'10.1.2.101'), 'server', bar='bar2') labels = {"labels": ["tom", "jerry"]} dbapi.hosts_labels_update(self.context, host_id, labels)
def test_hosts_get_all_with_label_filters(self): cloud_id = self.make_cloud(self.mock_project_id, 'cloud_1') region_id = self.make_region(self.mock_project_id, cloud_id, 'region_1') labels = {"labels": ["compute"]} host1 = self.make_host( self.mock_project_id, cloud_id, region_id, 'www1.example.com', IPAddress(u'10.1.2.101'), 'server', ) dbapi.hosts_labels_update(self.context, host1, labels) self.make_host( self.mock_project_id, cloud_id, region_id, 'www1.example2.com', IPAddress(u'10.1.2.102'), 'server', ) res, _ = dbapi.hosts_get_all(self.context, {"label": "compute"}, default_pagination) self.assertEqual(len(res), 1) self.assertEqual(res[0].name, 'www1.example.com')
def test_host_labels_delete(self): region_id = self.make_region('region_1', foo='R1') host_id = self.make_host(region_id, 'www.example.xyz', IPAddress(u'10.1.2.101'), 'server', bar='bar2') _labels = {"labels": ["tom", "jerry", "jones"]} dbapi.hosts_labels_update(self.context, host_id, _labels) host = dbapi.hosts_get_by_id(self.context, host_id) self.assertEqual(sorted(host.labels), sorted(_labels["labels"])) _dlabels = {"labels": ["tom"]} dbapi.hosts_labels_delete(self.context, host_id, _dlabels) host = dbapi.hosts_get_by_id(self.context, host_id) self.assertEqual(host.labels, {"jerry", "jones"})