Skip to content

Commit

Permalink
Merge pull request saltstack#47 from saltstack/RDTISALT-3192
Browse files Browse the repository at this point in the history
RDTISALT-3192 Run upstream unit tests but skip/xfail ones that are already broken
  • Loading branch information
clickthisnick2 authored and GitHub Enterprise committed Sep 9, 2019
2 parents 2775702 + 5fce0c2 commit 097d93a
Show file tree
Hide file tree
Showing 64 changed files with 862 additions and 639 deletions.
81 changes: 50 additions & 31 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@
def unique_container_name = "unit-tests-${env.BUILD_ID}${env.JOB_NAME.replace("/", "-")}"
def image_name = "artprod.dev.bloomberg.com/bb-inf/salt-minion:2018.3.3"

pipeline {
agent { label 'syscore-salt'}
environment {
BBGH_TOKEN = credentials('bbgithub_token')
PYPI_CREDENTIAL = credentials('salt_jenkins_ad_user_pass_escaped')
}
options {
ansiColor('xterm')
// Currently builds take an hour and 30 minutes.
// If every executor is used, this will give enough time for the queue to pass and this build to run
// timeout(time: 3, unit: 'HOURS')
// Keep up to 10 builds (artifacts/console output) from master and each branch retains up to 5 builds of that specific branch
buildDiscarder(logRotator(numToKeepStr: env.BRANCH_NAME == 'master' ? '10' : '5'))
}
stages {
stage('build') {
when {
changeRequest()
}
stage('Build') {
when {changeRequest()}
steps {
sh 'echo ========================'
sh 'echo running Build Stage'
sh 'whoami'
sh 'python --version'
sh 'hostname'
sh 'pwd'
sh 'printenv'
sh 'bash ./build/build.sh -b $CHANGE_ID'
}
}
stage('test') {
when {
changeRequest()
}
stage('Run Upstream Salt Unit Tests') {
when {changeRequest()}
steps {
sh 'echo ========================'
sh 'echo running Test Stage'
script {
// We are running inside a container so we can have the bbcpu.lst/alias
docker.withRegistry('https://artprod.dev.bloomberg.com', 'syscore_jenkins_docker_jwt_tuple') {
sh "docker pull ${image_name}"
}
// Jenkins docker integration is confusing wrapper and doesn't seem to work as expected
sh "docker run --name ${unique_container_name} -d -v `pwd`:`pwd`:ro -w `pwd` ${image_name}"
sh "docker exec ${unique_container_name} pip install -r requirements/dev_bloomberg.txt"

// Run whatever tests you want here for now. All tests takes like an hour.
// If you write custom tests, add them here so we are sure they continue passing
sh "docker exec ${unique_container_name} ./tests/runtests.py --unit -v"

// Whatever is failing we can skip with
// @expectedFailure #bb test was failing when ran in Jenkins
}
}
post {
cleanup {
node("syscore-salt") {
script {
deleteDir() /* clean up our workspace */

try {
sh "docker stop ${unique_container_name}"
} catch(Exception e) {
// continue
}
}
}
}
}
}
stage('deploy to dev pypi') {
when {
changeRequest()
}
stage('Deploy to dev pypi') {
when {changeRequest()}
steps {
sh 'echo ========================='
sh 'echo running Deploy to dev Stage'
sh 'bash ./build/build.sh -b $CHANGE_ID -k -s -u'
}
}
stage('deploy to ose pypi') {
when {
anyOf {
branch 'v2018.3.3-ca'
}
}
stage('Deploy to ose pypi') {
when {anyOf {branch 'v2018.3.3-ca'}}
steps {
sh 'echo ========================='
sh 'echo running Deploy to ose pypi Stage'
sh 'bash ./build/build.sh -u -p -t $BBGH_TOKEN_PSW'
}
}
Expand Down
18 changes: 9 additions & 9 deletions doc/man/salt.7
Original file line number Diff line number Diff line change
Expand Up @@ -379790,7 +379790,7 @@ from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch,
MagicMock,
Expand Down Expand Up @@ -379860,7 +379860,7 @@ a separate implementation which has additional functionality.
.sp
.nf
.ft C
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -379919,7 +379919,7 @@ those cases, you can pass \fBread_data\fP as a dictionary:
.ft C
import textwrap

from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -380012,7 +380012,7 @@ Instead of a string, an exception can also be used as the \fBread_data\fP:
.ft C
import errno

from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -380054,7 +380054,7 @@ and produce a mocked filehandle with the specified contents. For example:
import errno
import textwrap

from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -380173,7 +380173,7 @@ available via its \fBkwargs\fP attribute.
.sp
.nf
.ft C
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -380336,7 +380336,7 @@ Most commonly, the following imports are necessary to create a unit test:
.sp
.nf
.ft C
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
.ft P
.fi
.UNINDENT
Expand Down Expand Up @@ -380590,7 +380590,7 @@ import salt.modules.linux_sysictl as linux_sysctl

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.unit import skipIf, TestCase, expectedFailure
from tests.support.mock import (
MagicMock,
patch,
Expand Down Expand Up @@ -380699,7 +380699,7 @@ from salt.exceptions import CommandExecutionError

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.unit import skipIf, TestCase, expectedFailure
from tests.support.mock import (
MagicMock,
patch,
Expand Down
18 changes: 9 additions & 9 deletions doc/topics/development/tests/unit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Consider this more extensive example from
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch,
MagicMock,
Expand Down Expand Up @@ -196,7 +196,7 @@ a separate implementation which has additional functionality.

.. code-block:: python
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -251,7 +251,7 @@ those cases, you can pass ``read_data`` as a dictionary:
import textwrap
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -324,7 +324,7 @@ Instead of a string, an exception can also be used as the ``read_data``:
import errno
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -362,7 +362,7 @@ and produce a mocked filehandle with the specified contents. For example:
import errno
import textwrap
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -463,7 +463,7 @@ several useful attributes:

.. code-block:: python
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch
mock_open,
Expand Down Expand Up @@ -607,7 +607,7 @@ Most commonly, the following imports are necessary to create a unit test:

.. code-block:: python
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
If you need mock support to your tests, please also import:

Expand Down Expand Up @@ -824,7 +824,7 @@ will also redefine the ``__salt__`` dictionary such that it only contains
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.unit import skipIf, TestCase, expectedFailure
from tests.support.mock import (
MagicMock,
patch,
Expand Down Expand Up @@ -926,7 +926,7 @@ with.
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.unit import skipIf, TestCase, expectedFailure
from tests.support.mock import (
MagicMock,
patch,
Expand Down
13 changes: 13 additions & 0 deletions requirements/dev_bloomberg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-r base.txt
mock>=2.0.0
SaltPyLint>=v2017.3.6
pytest>=3.5.0
git+https://e904693b4b9f451885e6a05696ab0a60c3be959c:@bbgithub.dev.bloomberg.com/saltstack/pytest-salt.git@master#egg=pytest-salt
testinfra>=1.7.0
bloomberg.hostinfo
# httpretty Needs to be here for now even though it's a dependency of boto.
# A pip install on a fresh system will decide to target httpretty 0.8.10 to
# satisfy other requirements, and httpretty 0.8.10 has bugs in setup.py that
# prevent it from being successfully installed (at least on Python 3.4).
httpretty; python_version >= '3.4'
pylint==1.6.5
36 changes: 27 additions & 9 deletions salt/cloud/clouds/joyent.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,21 @@

try:
from M2Crypto import EVP
HAS_REQUIRED_CRYPTO = True
HAS_M2 = True
except ImportError:
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_v1_5
HAS_M2 = False
try:
from Cryptodome.Hash import SHA256
from Cryptodome.Signature import PKCS1_v1_5
HAS_REQUIRED_CRYPTO = True
except ImportError:
try:
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_v1_5
HAS_REQUIRED_CRYPTO = True
except ImportError:
HAS_REQUIRED_CRYPTO = False

# Import salt libs
from salt.ext import six
Expand Down Expand Up @@ -118,6 +128,8 @@ def __virtual__():
'''
Check for Joyent configs
'''
if HAS_REQUIRED_CRYPTO is False:
return False, 'Either PyCrypto or Cryptodome needs to be installed.'
if get_configured_provider() is False:
return False

Expand Down Expand Up @@ -360,7 +372,7 @@ def create_node(**kwargs):

data = salt.utils.json.dumps(create_data)

ret = query(command='/my/machines', data=data, method='POST',
ret = query(command='my/machines', data=data, method='POST',
location=location)
if ret[0] in VALID_RESPONSE_CODES:
return ret[1]
Expand Down Expand Up @@ -435,7 +447,7 @@ def reboot(name, call=None):
'''
node = get_node(name)
ret = take_action(name=name, call=call, method='POST',
command='/my/machines/{0}'.format(node['id']),
command='my/machines/{0}'.format(node['id']),
location=node['location'], data={'action': 'reboot'})
return ret[0] in VALID_RESPONSE_CODES

Expand All @@ -455,7 +467,7 @@ def stop(name, call=None):
'''
node = get_node(name)
ret = take_action(name=name, call=call, method='POST',
command='/my/machines/{0}'.format(node['id']),
command='my/machines/{0}'.format(node['id']),
location=node['location'], data={'action': 'stop'})
return ret[0] in VALID_RESPONSE_CODES

Expand All @@ -476,7 +488,7 @@ def start(name, call=None):
'''
node = get_node(name)
ret = take_action(name=name, call=call, method='POST',
command='/my/machines/{0}'.format(node['id']),
command='my/machines/{0}'.format(node['id']),
location=node['location'], data={'action': 'start'})
return ret[0] in VALID_RESPONSE_CODES

Expand Down Expand Up @@ -864,7 +876,7 @@ def avail_sizes(call=None):
'-f or --function, or with the --list-sizes option'
)

rcode, items = query(command='/my/packages')
rcode, items = query(command='my/packages')
if rcode not in VALID_RESPONSE_CODES:
return {}
return key_list(items=items)
Expand Down Expand Up @@ -1076,7 +1088,13 @@ def query(action=None,
hash_.update(timestamp.encode(__salt_system_encoding__))
signed = rsa_.sign(hash_)
signed = base64.b64encode(signed)
keyid = '/{0}/keys/{1}'.format(user.split('/')[0], ssh_keyname)
user_arr = user.split('/')
if len(user_arr) == 1:
keyid = '/{0}/keys/{1}'.format(user_arr[0], ssh_keyname)
elif len(user_arr) == 2:
keyid = '/{0}/users/{1}/keys/{2}'.format(user_arr[0], user_arr[1], ssh_keyname)
else:
log.error('Malformed user string')

headers = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -1118,4 +1136,4 @@ def query(action=None,
content = result['text']
return_content = salt.utils.yaml.safe_load(content)

return [result['status'], return_content]
return [result['status'], return_content]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch,
NO_MOCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase, skipIf, expectedFailure
from tests.support.mock import (
patch,
NO_MOCK,
Expand Down
Loading

0 comments on commit 097d93a

Please sign in to comment.