saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.17k stars 5.48k forks source link

[BUG] Updating labmda using boto_lambda.function_present is broken #58857

Open vshalchian opened 4 years ago

vshalchian commented 4 years ago

Description

boto_lambda.function_present can create a lambda function successfully however running the same state to update even if there is no change gives the following error :

     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3.6/site-packages/salt/state.py", line 2154, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/usr/lib/python3.6/site-packages/salt/loader.py", line 2188, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3.6/site-packages/salt/states/boto_lambda.py", line 354, in function_present
                  profile,
                File "/usr/lib/python3.6/site-packages/salt/states/boto_lambda.py", line 520, in _function_code_present
                  hashed = sha.digest().encode("base64").strip()
              AttributeError: 'bytes' object has no attribute 'encode'

Setup

create_function:
  boto_lambda.function_present:
    - name: myfunction
    - FunctionName: myfunction_name2
    - Runtime: python3.6
    - Role: labmda_role
    - Handler: main
    - ZipFile: /srv/salt/lambda/code/code.zip
    - profile: myprofile

Steps to Reproduce the behavior Try to create a simple lambda function using boto_lambda.function_present and run the state again. It always fails if the lambda exists. If you manually remove the lambda and run the state it works. it only fails when tries to update

Expected behavior When I edit the line 520 in /usr/lib/python3.6/site-packages/salt/states/boto_lambda.py and remove encode("base64") salt state works fine both for create and update

        Original : #hashed = sha.digest().encode("base64").strip()
        Changed to : hashed = sha.digest().strip()

Screenshots

Versions Report

salt-minion-3002-1.el7.noarch salt-master-3002-1.el7.noarch

# salt --versions-report
Salt Version:
           Salt: 3002

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.8.1
      docker-py: 2.6.1
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.11.1
        libgit2: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Apr  2 2020, 13:34:55)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.0.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: centos 7 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1127.19.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7 Core

Additional context Add any other context about the problem here.

welcome[bot] commented 4 years ago

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at core@saltstack.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

garethgreenaway commented 3 years ago

@vshalchian thanks for the report. Looks like this one is potentially an easy fix, would you be able to provide a PR with the changes? We'll help write some tests for it you need help as well.

vshalchian commented 3 years ago

@garethgreenaway here is the PR , please let me know if I need to do anything else https://github.com/saltstack/salt/pull/59470