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(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):
            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_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()
Пример #3
0
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()