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

Haproxy module feature = wait for defined time to shutdown connections #21676

Closed
artiombarb opened this issue Feb 20, 2017 · 6 comments
Closed
Labels
affects_2.1 This issue/PR affects Ansible v2.1 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. networking Network category

Comments

@artiombarb
Copy link

artiombarb commented Feb 20, 2017

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

haproxy module

ANSIBLE VERSION
ansible 2.1.1.0
  config file = 
  configured module search path = Default w/o overrides
CONFIGURATION

No changes

OS / ENVIRONMENT

Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
Linux ansible 2.6.32-042stab108.2 #1 SMP Tue May 12 18:07:50 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux

SUMMARY
Here is diff between original source code haproxy.py module and what I made.

108,110d107
< # disable backend server in 'www' backend pool and wait until connections gone. Retry 10 times with intervals of 5 seconds to retrieve open sessions and then drop it
< - haproxy: state=disabled host={{ inventory_hostname }} backend=www socket=/var/run/haproxy.sock wait_connections=true wait_retries=10 wait_interval=5 shutdown_sessions=true
< 
162d158
<         self.wait_connections = self.module.params['wait_connections']
218,233d213
<     def wait_close_connections(self, pxname, svname, connections):
< 
<         for i in range(1, self.wait_retries):
<             data = self.execute('show stat', 200, False).lstrip('# ')
<             r = csv.DictReader(data.splitlines())
<             found = False
<             for row in r:
<                 if row['pxname'] == pxname and row['svname'] == svname:
<                     found = True
<                     if row['scur'] == connections:
<                         return True;
<                     else:
<                         time.sleep(self.wait_interval)
<             if not found:
<                 self.module.fail_json(msg="unable to find server %s/%s" % (pxname, svname))
< 
315d294
< 		    self.execute(cmd)
318,320c297
<                         if self.wait_connections:
<                             self.wait_close_connections(pxname, svname, '0')
<                         self.execute(cmd)
---
>                     self.execute(cmd)
327d303
< 	    self.execute(cmd)
330,332c306
<                 if self.wait_connections:
<                     self.wait_close_connections(pxname, svname, '0')
<                 self.execute(cmd)
---
>             self.execute(cmd)
378d351
< 	    wait_connections=dict(required=False, default=False, type='bool'),
STEPS TO REPRODUCE

Disable backend server in backend pool and wait until connections gone. Retry times with intervals of seconds to retrieve open sessions and then drop it.

- hosts: haproxy-node
  become: yes
  become_user: root
  serial: 1
  tasks:
    - name: haproxy set mtain to maintenance state
      haproxy:
        state: disabled
        host: '{{ item.host }}'
        backend: '{{ item.backend }}'
        socket: /var/lib/haproxy/stats
        wait: yes
        wait_retries: 5
        wait_interval: 5
      with_items:
        - { host: "{{ inventory_hostname }}", backend: 'b' }
        - { host: "{{ inventory_hostname }}", backend: 'b-ssl' }
    - name: haproxy check mtain connections
      haproxy:
        state: disabled
        host: '{{ item.host }}'
        backend: '{{ item.backend }}'
        socket: /var/lib/haproxy/stats
        wait_connections: true
        wait: yes
        wait_retries: 10
        wait_interval: 60
        shutdown_sessions: true
      with_items:
        - { host: "{{ inventory_hostname }}", backend: 'b }
        - { host: "{{ inventory_hostname }}", backend: 'b-ssl' }
    - name: haproxy set to ready state
      haproxy:
        state: enabled
        host: '{{ item.host }}'
        backend: '{{ item.backend }}'
        socket: /var/lib/haproxy/stats
        wait: yes
        wait_retries: 5
        wait_interval: 5
      with_items:
       - { host: "{{ inventory_hostname }}", backend: 'b' }
       - { host: "{{ inventory_hostname }}", backend: 'b-ssl' }
EXPECTED RESULTS

Expect to wait for defined wait time = <retry_number>*<interval_time> and then drop connections by using option "shutdown_sessions=true"

ACTUAL RESULTS
Work as described, waits for defined wait time = <retry_number>*<interval_time> and then drop connections by using option "shutdown_sessions=true"
@ansibot
Copy link
Contributor

ansibot commented Feb 20, 2017

@ansibot ansibot added affects_2.1 This issue/PR affects Ansible v2.1 feature_idea module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. networking Network category labels Feb 20, 2017
@alikins
Copy link
Contributor

alikins commented Feb 20, 2017

@artiombarb Could you make this diff into a pull request? That helps preserve attribution.

@alikins alikins removed the needs_triage Needs a first human triage before being processed. label Feb 20, 2017
@ravibhure
Copy link
Contributor

@artiombarb please send PR

@artiombarb
Copy link
Author

I'am going to work on code for ansible-2.2 version.

@artiombarb
Copy link
Author

Could you be so kind and help me. How I can correctly commit and make PR to ansible 2.1?
Thank you in advance.

@artiombarb
Copy link
Author

I think this is not relevant cause I made PR to ansible 2.3

@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_idea labels Mar 2, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. networking Network category
Projects
None yet
Development

No branches or pull requests

4 participants