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

[Question] About the operation when the pcs command is wrapped in perl etc.. #612

Closed
HideoYamauchi opened this issue Dec 21, 2022 · 3 comments · Fixed by #661
Closed

[Question] About the operation when the pcs command is wrapped in perl etc.. #612

HideoYamauchi opened this issue Dec 21, 2022 · 3 comments · Fixed by #661
Assignees

Comments

@HideoYamauchi
Copy link
Contributor

Hi All

We have implemented a perl wrapper to make it easier to use pcs on RHEL9.1.

#!/usr/bin/perl
sub exec_command {
    my ($command) = @_;
    my $result;
    my $exit_code;
    $result = `$command`;
    $exit_code = $? >> 8;
    if ($exit_code != 0){
        printf("ERROR\n");
    }
    return $result;
}

my $input = <STDIN>;
chomp $input;
if ($input !~ m/^y$/i) {
    exit(0);
}

close STDIN;

exec_command("/usr/sbin/pcs cluster destroy --all --force");

The pcs command will generate an error if STDIN is closed on the perl side when executing wrap processing with confirmation processing such as the following.

[root@rh91-01 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 9.1 (Plow)
[root@rh91-01 ~]# pcs --version
0.11.3

[root@rh91-01 ~]# ./test.pl
y
Traceback (most recent call last):
  File "/usr/sbin/pcs", line 33, in <module>
    sys.exit(load_entry_point('pcs==0.11.3', 'console_scripts', 'pcs')())
  File "/usr/lib/python3.9/site-packages/pcs/app.py", line 273, in main
    routing.create_router(cmd_map, [])(
  File "/usr/lib/python3.9/site-packages/pcs/cli/common/routing.py", line 33, in _router
    return cmd_map[sub_cmd](lib, argv_next, modifiers)
  File "/usr/lib/python3.9/site-packages/pcs/cli/common/routing.py", line 33, in _router
    return cmd_map[sub_cmd](lib, argv_next, modifiers)
  File "/usr/lib/python3.9/site-packages/pcs/cluster.py", line 1266, in cluster_destroy
    if utils.is_run_interactive():
  File "/usr/lib/python3.9/site-packages/pcs/utils.py", line 2059, in is_run_interactive
    return sys.stdin.isatty() and sys.stdout.isatty()
AttributeError: 'NoneType' object has no attribute 'isatty'
ERROR

Conversely, if STDIN is not closed, the pcs command will not generate an error.

[root@rh91-01 ~]# ./test.pl
y
Warning: Unable to load CIB to get guest and remote nodes from it, those nodes will not be deconfigured.
rh91-02: Stopping Cluster (pacemaker)...
rh91-01: Stopping Cluster (pacemaker)...
rh91-02: Successfully destroyed cluster
rh91-01: Successfully destroyed cluster
[root@rh91-01 ~]# 

I think that the process of closing STDIN used on the perl side is in the normal implementation.

It seems to be a problem of isatty processing on the pcs side, but is it possible to deal with it?

Best Regards,
Hideo Yamauchi.

@tomjelinek
Copy link
Member

Hi @HideoYamauchi,

Thank you for reaching out. It seems you found a bug in pcs. Apparently, sys.stdin as well as sys.stdout and sys.stderr can be None. We should update pcs to check if they are not None before we access their isatty method.

@HideoYamauchi
Copy link
Contributor Author

Hi Tomas,

Thank you for reaching out. It seems you found a bug in pcs. Apparently, sys.stdin as well as sys.stdout and sys.stderr can be None. We should update pcs to check if they are not None before we access their isatty method.

Thanks for your comment.

I understand that there is a problem with pcs.
For the time being, I will consider some kind of correspondence in the wrapping process.

Many thaks,
Hideo Yamauchi.,

@HideoYamauchi
Copy link
Contributor Author

Hi All,

Thanks for the correction.

Best Regards,
Hideo Yamauchi.

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 a pull request may close this issue.

3 participants