def test_render(patch_etcd_utils_read, patch_get_node_id, patch_write, patch_read, patch_client): setattr(__builtin__, "NS", maps.NamedDict()) NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}') with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() node_context.render()
def test_render(patch_etcd_utils_read, patch_get_node_id, patch_write, patch_read, patch_client): setattr(__builtin__, "NS", maps.NamedDict()) NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = { 'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}') with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() node_context.render()
def test_update_cluster_details(patch_get_node_id, patch_client, patch_etcd_utils_read): setattr(__builtin__, "NS", maps.NamedDict()) NS.publisher_id = "Test_node_context" NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 NS.node_context.tags = ["tendrl/monitor"] NS.node_context.fqdn = "test_fqdn" patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = { 'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS._int.wclient = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = ["tendrl/integration/monitoring", "tendrl/node_28c93b1d-361c-\ 4b32-acc0-f405d2a05eca", "tendrl/central-store", "tendrl/server", "tendrl/monitor", "tendrl/node", "provisioner/1"] NS._int.watchers = dict() NS.tendrl = maps.NamedDict() NS.tendrl.objects = maps.NamedDict() NS.tendrl.objects.Job = MockJob patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}', leaves=[maps.NamedDict(key='test_value')]) NS.tendrl.objects.TendrlContext = MockTendrlContext NS.tendrl.objects.ClusterNodeContext = MockCNC_down NS.tendrl_context = MockTendrlContext() NS.tendrl.objects.GlobalDetails = MockGlobalDetails NS.tendrl.objects.Cluster = Cluster NS.tendrl.objects.GlusterBrick = MockGlusterBrick NS.tendrl.objects.GlusterVolume = MockGlusterVolume with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() node_context.update_cluster_details("1")
def test_update_cluster_details(patch_get_node_id, patch_client, patch_etcd_utils_read): setattr(__builtin__, "NS", maps.NamedDict()) NS.publisher_id = "Test_node_context" NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 NS.node_context.tags = ["tendrl/monitor"] NS.node_context.fqdn = "test_fqdn" patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS._int.wclient = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = [ "tendrl/integration/monitoring", "tendrl/node_28c93b1d-361c-\ 4b32-acc0-f405d2a05eca", "tendrl/central-store", "tendrl/server", "tendrl/monitor", "tendrl/node", "provisioner/1" ] NS._int.watchers = dict() NS.tendrl = maps.NamedDict() NS.tendrl.objects = maps.NamedDict() NS.tendrl.objects.Job = MockJob patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}', leaves=[maps.NamedDict(key='test_value')]) NS.tendrl.objects.TendrlContext = MockTendrlContext NS.tendrl.objects.ClusterNodeContext = MockCNC_down NS.tendrl_context = MockTendrlContext() NS.tendrl.objects.GlobalDetails = MockGlobalDetails NS.tendrl.objects.Cluster = Cluster NS.tendrl.objects.GlusterBrick = MockGlusterBrick NS.tendrl.objects.GlusterVolume = MockGlusterVolume with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() node_context.update_cluster_details("1")
def test_create_node_id(patch_write, patch_read, patch_client): setattr(__builtin__, "NS", maps.NamedDict()) NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS._int.wclient = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" node_context = NodeContext(machine_id="Test_Machine_id", node_id="Test_Node_id", fqdn="Test_fqdn") f = tempfile.TemporaryFile() with patch.object(__builtin__, "open") as mock_open: mock_open.return_value = f with patch.object(os, "makedirs", return_value=True) as mock_makedirs: node_context._create_node_id() f.close() with pytest.raises(IOError): with patch.object(os, "makedirs", return_value=True) as mock_makedirs: node_context._create_node_id() f = tempfile.TemporaryFile() with patch.object(__builtin__, "open") as mock_open: mock_open.return_value = f with patch.object(os.path, "exists", return_value=False) as mock_exists: with patch.object(os, "makedirs", return_value=True) as mock_makedirs: node_context._create_node_id() f.close()
def test_render(patch_get_node_id, patch_write, patch_read, patch_client): setattr(__builtin__, "NS", maps.NamedDict()) NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() node_context.render()
def test_get_node_id(patch_etcd_utils_read, patch_read, patch_client): patch_read.return_value = maps.NamedDict(value=u'"testing"') patch_client.return_value = etcd.Client() setattr(__builtin__, "NS", maps.NamedDict()) setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}') with patch.object(os.path, "isfile", return_value=True): with mock.patch("__builtin__.open", create=True) as mock_open: mock_open.side_effect = [ mock.mock_open(read_data="8eccbee-1e88-4232-9877-61d0ea595930" "").return_value ] NodeContext()._get_node_id()
def test_constructor(patch_etcd_utils_read, patch_get_node_id, patch_client): '''Testing for constructor involves checking if all needed variables are declared initialized ''' patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(__builtin__, "NS", maps.NamedDict()) setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}') with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() assert node_context is not None
def test_create_node_id(patch_etcd_utils_read, patch_write, patch_read, patch_client): setattr(__builtin__, "NS", maps.NamedDict()) NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = { 'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS._int.wclient = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}') with patch.object(socket, "gethostbyname") as gethostbyname: gethostbyname.return_value = "127.0.0.1" node_context = NodeContext(node_id="Test_Node_id", fqdn="Test_fqdn", ipv4_addr="127.0.0.1") f = tempfile.TemporaryFile() with patch.object(__builtin__, "open") as mock_open: mock_open.return_value = f with patch.object(os, "makedirs", return_value=True): node_context._create_node_id() f.close() f = tempfile.TemporaryFile() with patch.object(__builtin__, "open") as mock_open: mock_open.return_value = f with patch.object(os.path, "exists", return_value=False): with patch.object(os, "makedirs", return_value=True): node_context._create_node_id() f.close()
def test_get_machine_id(patch_write, patch_read, patch_client): patch_read.return_value = "8ceccbee-1e88-4232-9877-61d0ea595930" patch_write.return_value = etcd.Client() patch_client.return_value = etcd.Client() setattr(__builtin__, "NS", maps.NamedDict()) setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS._int.wclient = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" node_context = NodeContext(machine_id="Test_Machine_id", node_id="Test_Node_id", fqdn="Test_fqdn") def open(*args): raise IOError with patch.object(__builtin__, "open", open) as mock_open: ret = node_context._get_machine_id()
def test_get_node_id(patch_read, patch_client): patch_read.return_value = "8ceccbee-1e88-4232-9877-61d0ea595930" patch_client.return_value = etcd.Client() setattr(__builtin__, "NS", maps.NamedDict()) setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" with patch.object(os.path, "isfile", return_value=True): with mock.patch("__builtin__.open", create=True) as mock_open: mock_open.side_effect = [ mock.mock_open(read_data="8eccbee-1e88-4232-9877-61d0ea595930" "").return_value ] with pytest.raises(Exception): NodeContext() with patch.object(os.path, "isfile", return_value=False): with patch.object(NodeContext, "_create_node_id", return_value=None): NodeContext()
def test_constructor(patch_get_node_id, patch_client): '''Testing for constructor involves checking if all needed variables are declared initialized ''' patch_get_node_id.return_value = 1 patch_client.return_value = etcd.Client() setattr(__builtin__, "NS", maps.NamedDict()) setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" with patch.object(etcd.Client, "read", return_value=etcd.Client()): node_context = NodeContext() assert node_context is not None
def test_create_node_id(patch_etcd_utils_read, patch_write, patch_read, patch_client): setattr(__builtin__, "NS", maps.NamedDict()) NS.node_context = maps.NamedDict() NS.node_context.node_id = 1 patch_client.return_value = etcd.Client() setattr(NS, "_int", maps.NamedDict()) NS._int.etcd_kwargs = {'port': 1, 'host': 2, 'allow_reconnect': True} NS._int.client = etcd.Client(**NS._int.etcd_kwargs) NS._int.wclient = etcd.Client(**NS._int.etcd_kwargs) NS["config"] = maps.NamedDict() NS.config["data"] = maps.NamedDict() NS.config.data['tags'] = "test" patch_etcd_utils_read.return_value = maps.NamedDict( value='{"status": "UP",' '"pkey": "tendrl-node-test",' '"node_id": "test_node_id",' '"ipv4_addr": "test_ip",' '"tags": "[\\"my_tag\\"]",' '"sync_status": "done",' '"locked_by": "fd",' '"fqdn": "tendrl-node-test",' '"last_sync": "date"}') with patch.object(socket, "gethostbyname") as gethostbyname: gethostbyname.return_value = "127.0.0.1" node_context = NodeContext(node_id="Test_Node_id", fqdn="Test_fqdn", ipv4_addr="127.0.0.1") f = tempfile.TemporaryFile() with patch.object(__builtin__, "open") as mock_open: mock_open.return_value = f with patch.object(os, "makedirs", return_value=True): node_context._create_node_id() f.close() f = tempfile.TemporaryFile() with patch.object(__builtin__, "open") as mock_open: mock_open.return_value = f with patch.object(os.path, "exists", return_value=False): with patch.object(os, "makedirs", return_value=True): node_context._create_node_id() f.close()