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

Add create-network cli command #524

Merged
merged 4 commits into from
Sep 10, 2024
Merged

Add create-network cli command #524

merged 4 commits into from
Sep 10, 2024

Conversation

m3dwards
Copy link
Collaborator

@m3dwards m3dwards commented Sep 4, 2024

Look @pinheadmz, a test!

Copy link
Collaborator

@josibake josibake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code review ACK, looks good. I do think its worth changing warnet create to mean create a network in this PR, and either only having warnet init or warnet new and init for starting a project.



@click.command()
def create_network():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! @willcl-ark had suggested previously we use warnet init and warnet new for initialising or creating new project directories. this matches cargo's new/init.

if we did that, we could just use warnet create for creating a new network? I prefer the smaller cli command names and I don't envision a user creating anything but a new network.

we could also just have one command for initialising, e.g. warnet init and use warnet create for creating a network, which would be easy enough to do in this PR, and then we can add warnet new later if we feel its needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about dropping create / new?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id be fine to only have warnet init. initially I was thinking warnet create would be helpful when you want to manage multiple warnet directories, but starting to feel like no one uses it and it was premature optimisation.

id much rather we have warnet init and then have warnet create for creating networks.

Copy link
Collaborator Author

@m3dwards m3dwards Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in df2856d

Copy link
Contributor

@willcl-ark willcl-ark Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo has cargo init and cargo new which IMO make sense. Both make a new project, one in current dir, and one in the dir provided as arg.

No strong opinion though

yaml.dump(network_yaml_data, f, default_flow_style=False)

# Generate defaults.yaml
default_yaml_path = files("resources.networks").joinpath("6_node_bitcoin/node-defaults.yaml")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: we should move all the hardcoded values into something like config.py or constants.py , so these can be something like default_yaml_path = config.DEFAULT_YAML_PATH etc

@pinheadmz
Copy link
Contributor

not sure what to make of this....?

(.venv) --> test/graph_test.py
2024-09-04 11:09:59 | INFO    | test     | Logging started
2024-09-04 11:09:59 | INFO    | test     | Warnet test base initialized
Traceback (most recent call last):
  File "/Users/matthewzipkin/Desktop/work/warnet/test/graph_test.py", line 44, in <module>
    test.run_test()
  File "/Users/matthewzipkin/Desktop/work/warnet/test/graph_test.py", line 20, in run_test
    self.directory_exists()
  File "/Users/matthewzipkin/Desktop/work/warnet/test/graph_test.py", line 39, in directory_exists
    self.sut.expect("successfully", timeout=5)
  File "/Users/matthewzipkin/Desktop/work/warnet/.venv/lib/python3.12/site-packages/pexpect/spawnbase.py", line 354, in expect
    return self.expect_list(compiled_pattern_list,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthewzipkin/Desktop/work/warnet/.venv/lib/python3.12/site-packages/pexpect/spawnbase.py", line 383, in expect_list
    return exp.expect_loop(timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthewzipkin/Desktop/work/warnet/.venv/lib/python3.12/site-packages/pexpect/expect.py", line 181, in expect_loop
    return self.timeout(e)
           ^^^^^^^^^^^^^^^
  File "/Users/matthewzipkin/Desktop/work/warnet/.venv/lib/python3.12/site-packages/pexpect/expect.py", line 144, in timeout
    raise exc
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x102e76600>
command: /Users/matthewzipkin/Desktop/work/warnet/.venv/bin/warnet
args: ['/Users/matthewzipkin/Desktop/work/warnet/.venv/bin/warnet', 'create-network']
buffer (last 100 chars): b'[m\x0f  26.0\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  25.1\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  24.2\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  23.2\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  22.2\x1b[m\x0f\x1b[K\r\n\r\n'
before (last 100 chars): b'[m\x0f  26.0\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  25.1\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  24.2\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  23.2\x1b[m\x0f\x1b[K\r\n \x1b[m\x0f  22.2\x1b[m\x0f\x1b[K\r\n\r\n'
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 14835
child_fd: 8
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
    0: re.compile(b'successfully')
2024-09-04 11:10:05 | INFO    | test     | Stopping network
2024-09-04 11:10:05 | DEBUG   | test     | Executing warnet command: down

@m3dwards
Copy link
Collaborator Author

m3dwards commented Sep 4, 2024

not sure what to make of this

hmm, not sure, could be that the timeout needs to be longer. I assumed it was seconds but perhaps it's milliseconds.

@m3dwards m3dwards force-pushed the network-create branch 3 times, most recently from 3bda429 to 05bdefe Compare September 4, 2024 15:31
@m3dwards
Copy link
Collaborator Author

m3dwards commented Sep 4, 2024

Care to give it another go @pinheadmz ?

Copy link
Collaborator

@josibake josibake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code review ACK, thanks for taking the naming suggestion for the cli command

# Check if the project has a networks directory
if not (project_path / "networks").exists():
click.secho(
"The current directory does not have a 'networks' directory. Please run 'warnet init' or 'warnet create' first.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to update this help text now that we only have warnet init

@pinheadmz
Copy link
Contributor

Test passed for me locally now, but CI doesnt look happy even though its green:
https://github.com/bitcoin-dev-project/warnet/actions/runs/10704964245/job/29679197963#step:5:78

Quick guess is test_base tries to call "warnet down" even though it was never up

@pinheadmz
Copy link
Contributor

ACK, modulo weird test down thing. can be fixed in follow up

@josibake
Copy link
Collaborator

josibake commented Sep 4, 2024

ACK, modulo weird test down thing. can be fixed in follow up

was also running into this on a diff branch, iirc. I think we just need to fix warnet down so that if you call down and there's nothing there, it just gracefully exits (assuming that's actually the issue here)

@josibake
Copy link
Collaborator

josibake commented Sep 8, 2024

would be nice to get this in, can you rebase @m3dwards ? otherwise I can take a crack at resolving the merge conflicts

@bdp-DrahtBot
Copy link
Collaborator

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #553 (add k8s log collector to CI by willcl-ark)
  • #531 (unified HTML landing page (NOT a dashboard!) by willcl-ark)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@m3dwards
Copy link
Collaborator Author

m3dwards commented Sep 9, 2024

Rebased after #536

@josibake josibake merged commit dd22649 into main Sep 10, 2024
14 checks passed
@m3dwards m3dwards deleted the network-create branch September 10, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants