Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows - Unable to delete a lab in a subdirectory #93

Open
seanblundy opened this issue Jan 16, 2022 · 4 comments · Fixed by #62
Open

Windows - Unable to delete a lab in a subdirectory #93

seanblundy opened this issue Jan 16, 2022 · 4 comments · Fixed by #62
Labels
bug Something isn't working

Comments

@seanblundy
Copy link

Summary

I am unable to remove a nested lab via this library.

Issue Type

Bug Report

Python Version

3.8.10

OS / Environment

Windows 10

Steps to Reproduce

On a Windows system, attempt to delete a lab in a subdirectory.

Expected Results

Lab is deleted successfully.

Actual Results

Exception has occurred: ValueError
WindowsPath('//Ansible/test_lab.unl/') has an empty name
  File "C:\Projects\autolab\app.py", line 22, in <module>
    client.api.delete_lab(lab)

Comments

This is due to the Path import being ambiguous, and as a result will use the system Pathlib, which in my case is WindowsPath.

Discovered Solution

By replacing the import with PurePosixPath and removing the .resolve(), I am able to utilize the SDK. Perhaps introduce a check for the OS the user is on and substitute these function calls?

from pathlib import Path

path = Path(path).resolve()

@seanblundy seanblundy changed the title Unable to delete a lab in a subdirectory Windows - Unable to delete a lab in a subdirectory Jan 16, 2022
@ttafsir ttafsir added the bug Something isn't working label Jan 17, 2022
@mplattner
Copy link
Contributor

mplattner commented Jan 17, 2022

There's already a PR that fixes this. It's applied in the develop branch, but I guess will be in the main branch as well soon. See #62

@ttafsir ttafsir mentioned this issue Jan 17, 2022
This was linked to pull requests Jan 18, 2022
@ttafsir ttafsir removed a link to a pull request Jan 18, 2022
@ttafsir
Copy link
Owner

ttafsir commented Jan 18, 2022

I pulled the changes in, but I have no real way to test without Windows. Please let me know. Thank you!!

@seanblundy
Copy link
Author

seanblundy commented Jan 25, 2022

So, an update with 0.2.2:

It works.

However, it only works when the path is correctly specified. (e.g. /Ansible/test_lab.unl). The downside here being that the eve-ng API returns poor POSIX paths such as: //Ansible/test_lab.unl, which are natively handled on Unix gracefully (Tested via Ubuntu 20.04), but not Windows.

Steps to Reproduce:

As a result of this, attempting to use a direct output of the API results in:

>>> from pathlib import PurePosixPath
>>> resp = client.api.get_folder("/")
>>> resp
{
  "code": 200,
  "status": "success",
  "message": "Successfully listed path (60007).",
  "data": {
    "folders": [
      { "name": "..", "path": "/" },
      { "name": "Ansible", "path": "///Ansible" }
    ],
    "labs": []
  }
}

>>> folder = 'Ansible'
>>> resp = client.api.get_folder(folder)
>>> resp
{
  "code": 200,
  "status": "success",
  "message": "Successfully listed path (60007).",
  "data": {
    "folders": [{ "name": "..", "path": "/" }],
    "labs": [
      {
        "file": "test_lab.unl",
        "path": "//Ansible/test_lab.unl",
        "umtime": 1643087601,
        "mtime": "25 Jan 2022  06:13"
      }
    ]
  }
}

>>> lab = resp['data']['labs'][0]['path']
>>> lab
'//Ansible/test_lab.unl'
>>> client.api.delete_lab(lab)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\\Projects\autolab\venv\lib\site-packages\evengsdk\api.py", line 767, in delete_lab
    url = "/labs" + self.normalize_path(path)
  File "C:\\Projects\autolab\venv\lib\site-packages\evengsdk\api.py", line 155, in normalize_path
    path = path.with_suffix(".unl")
  File "C:\Python38\lib\pathlib.py", line 872, in with_suffix
    raise ValueError("%r has an empty name" % (self,))
ValueError: WindowsPath('//Ansible/test_lab.unl/') has an empty name

@ttafsir
Copy link
Owner

ttafsir commented Jan 26, 2022

So, an update with 0.2.2:

It works.

However, it only works when the path is correctly specified. (e.g. /Ansible/test_lab.unl). The downside here being that the eve-ng API returns poor POSIX paths such as: //Ansible/test_lab.unl, which are natively handled on Unix gracefully (Tested via Ubuntu 20.04), but not Windows.

Steps to Reproduce:

As a result of this, attempting to use a direct output of the API results in:

>>> from pathlib import PurePosixPath
>>> resp = client.api.get_folder("/")
>>> resp
{
  "code": 200,
  "status": "success",
  "message": "Successfully listed path (60007).",
  "data": {
    "folders": [
      { "name": "..", "path": "/" },
      { "name": "Ansible", "path": "///Ansible" }
    ],
    "labs": []
  }
}

>>> folder = 'Ansible'
>>> resp = client.api.get_folder(folder)
>>> resp
{
  "code": 200,
  "status": "success",
  "message": "Successfully listed path (60007).",
  "data": {
    "folders": [{ "name": "..", "path": "/" }],
    "labs": [
      {
        "file": "test_lab.unl",
        "path": "//Ansible/test_lab.unl",
        "umtime": 1643087601,
        "mtime": "25 Jan 2022  06:13"
      }
    ]
  }
}

>>> lab = resp['data']['labs'][0]['path']
>>> lab
'//Ansible/test_lab.unl'
>>> client.api.delete_lab(lab)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\\Projects\autolab\venv\lib\site-packages\evengsdk\api.py", line 767, in delete_lab
    url = "/labs" + self.normalize_path(path)
  File "C:\\Projects\autolab\venv\lib\site-packages\evengsdk\api.py", line 155, in normalize_path
    path = path.with_suffix(".unl")
  File "C:\Python38\lib\pathlib.py", line 872, in with_suffix
    raise ValueError("%r has an empty name" % (self,))
ValueError: WindowsPath('//Ansible/test_lab.unl/') has an empty name

I see. I should have a Windows set up here pretty soon to see if I can replicate the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants