mirror of
https://github.com/openSUSE/osc.git
synced 2025-09-07 05:38:43 +02:00
Add behave tests
This commit is contained in:
24
behave/features/add.feature
Normal file
24
behave/features/add.feature
Normal file
@@ -0,0 +1,24 @@
|
||||
@no-snapshot
|
||||
Feature: `osc add` command
|
||||
|
||||
|
||||
Scenario: Run `osc add` on a new file in a package
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "checkout openSUSE:Factory test-pkgA"
|
||||
And I set working directory to "{context.osc.temp}/openSUSE:Factory/test-pkgA"
|
||||
And I copy file "{context.fixtures}/pac/test-pkgA-1.spec" to "{context.osc.temp}/openSUSE:Factory/test-pkgA/new_file"
|
||||
And I execute osc with args "status --verbose"
|
||||
And stdout is
|
||||
"""
|
||||
? new_file
|
||||
test-pkgA.changes
|
||||
test-pkgA.spec
|
||||
"""
|
||||
When I execute osc with args "add new_file"
|
||||
And I execute osc with args "status --verbose"
|
||||
Then stdout is
|
||||
"""
|
||||
A new_file
|
||||
test-pkgA.changes
|
||||
test-pkgA.spec
|
||||
"""
|
76
behave/features/checkout.feature
Normal file
76
behave/features/checkout.feature
Normal file
@@ -0,0 +1,76 @@
|
||||
@no-snapshot
|
||||
Feature: `osc checkout` command
|
||||
|
||||
|
||||
Scenario: Run `osc checkout` on a project
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory"
|
||||
Then directory "{context.osc.temp}/openSUSE:Factory" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/.osc" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgA" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgA/.osc" exists
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.spec" exists
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.changes" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgB" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgB/.osc" exists
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgB/test-pkgB.spec" exists
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgB/test-pkgB.changes" exists
|
||||
|
||||
|
||||
Scenario: Run `osc checkout` on a package
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory test-pkgA"
|
||||
Then directory "{context.osc.temp}/openSUSE:Factory" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/.osc" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgA" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgA/.osc" exists
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.spec" exists
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.changes" exists
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgB" does not exist
|
||||
|
||||
|
||||
# Unlike other checkouts, file checkout doesn't create any subdirs
|
||||
# and puts files directly in the working directory.
|
||||
Scenario: Run `osc checkout` on a file
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory test-pkgA test-pkgA.spec"
|
||||
Then directory "{context.osc.temp}/openSUSE:Factory" does not exist
|
||||
And file "{context.osc.temp}/test-pkgA.spec" exists
|
||||
And file "{context.osc.temp}/test-pkgA.changes" does not exist
|
||||
|
||||
|
||||
Scenario: Run `osc checkout` on a package, use a file size limit
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory test-pkgA --limit-size=200"
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.spec" does not exist
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.changes" exists
|
||||
|
||||
|
||||
Scenario: Run `osc checkout` on a package in a specified revision
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory test-pkgA --revision=2"
|
||||
Then file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.spec" is identical to "{context.fixtures}/pac/test-pkgA-2.spec"
|
||||
And file "{context.osc.temp}/openSUSE:Factory/test-pkgA/test-pkgA.changes" is identical to "{context.fixtures}/pac/test-pkgA-2.changes"
|
||||
|
||||
|
||||
Scenario: Run `osc checkout` on a package, place the files in a specified output directory
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory test-pkgA --output-dir=pkgA"
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgA" does not exist
|
||||
And directory "{context.osc.temp}/pkgA" exists
|
||||
And directory "{context.osc.temp}/pkgA/.osc" exists
|
||||
And file "{context.osc.temp}/pkgA/test-pkgA.spec" exists
|
||||
And file "{context.osc.temp}/pkgA/test-pkgA.changes" exists
|
||||
|
||||
|
||||
# TODO(dmach): revisit this functionality
|
||||
# Working dir becomes a project dir, package goes into a subdirectory.
|
||||
# One would expect the package to go to the working dir.
|
||||
Scenario: Run `osc checkout` on a package, place the files in the working directory
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
When I execute osc with args "checkout openSUSE:Factory test-pkgA --current-dir"
|
||||
And directory "{context.osc.temp}/openSUSE:Factory/test-pkgA" does not exist
|
||||
And directory "{context.osc.temp}/.osc" exists
|
||||
And directory "{context.osc.temp}/test-pkgA/.osc" exists
|
||||
And file "{context.osc.temp}/test-pkgA/test-pkgA.spec" exists
|
||||
And file "{context.osc.temp}/test-pkgA/test-pkgA.changes" exists
|
57
behave/features/environment.py
Normal file
57
behave/features/environment.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import os
|
||||
|
||||
from steps import kanku
|
||||
from steps import osc
|
||||
from steps import common
|
||||
|
||||
|
||||
def before_step(context, step):
|
||||
pass
|
||||
|
||||
|
||||
def after_step(context, step):
|
||||
pass
|
||||
|
||||
|
||||
def before_scenario(context, scenario):
|
||||
context.osc = osc.Osc(context)
|
||||
|
||||
|
||||
def after_scenario(context, scenario):
|
||||
common.check_exit_code(context)
|
||||
del context.osc
|
||||
|
||||
|
||||
def before_feature(context, feature):
|
||||
# decorate Feature with @no-snapshot to avoid doing a snapshot rollback
|
||||
if "no-snapshot" not in feature.tags:
|
||||
context.kanku.revert_to_snapshot()
|
||||
|
||||
|
||||
def after_feature(context, feature):
|
||||
pass
|
||||
|
||||
|
||||
def after_tag(context, tag):
|
||||
pass
|
||||
|
||||
|
||||
def before_all(context):
|
||||
# convert path to osc executable to an absolute path to avoid relative path issues
|
||||
if "osc" in context.config.userdata:
|
||||
context.config.userdata["osc"] = os.path.abspath(os.path.expanduser(context.config.userdata["osc"]))
|
||||
|
||||
# absolute path to .../behave/fixtures
|
||||
context.fixtures = os.path.join(os.path.dirname(__file__), "..", "fixtures")
|
||||
|
||||
kankufile = os.path.join(os.path.dirname(__file__), "..", "KankuFile")
|
||||
context.kanku = kanku.Kanku(context, kankufile)
|
||||
|
||||
# This fails if the snapshot exists already.
|
||||
# It's ok in most cases, because it's the same snapshot we'd normally create.
|
||||
context.kanku.create_snapshot()
|
||||
|
||||
|
||||
def after_all(context):
|
||||
del context.kanku
|
||||
del context.fixtures
|
@@ -0,0 +1,67 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <project> <package> <repo> <arch> <file>` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 multibuild-pkg-1-1.1.x86_64.rpm"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file> --multibuild-package=<flavor>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 multibuild-pkg-flavor1-1-1.1.x86_64.rpm --multibuild-package=flavor1"
|
||||
# the option is allowed only in a package checkout
|
||||
Then the exit code is 2
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package>:<flavor> <repo> <arch> <file>` where file is a package
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg:flavor1 standard x86_64 multibuild-pkg-flavor1-1-1.1.x86_64.rpm"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file>` where file is a source package
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 multibuild-pkg-1-1.1.src.rpm"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file> --source` where file is a source package
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 multibuild-pkg-1-1.1.src.rpm --source"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file>` where file is a debuginfo package
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 multibuild-pkg-debuginfo-1-1.1.x86_64.rpm"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file> --debuginfo` where file is a debuginfo package
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 multibuild-pkg-debuginfo-1-1.1.x86_64.rpm --debuginfo"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-debuginfo-1-1.1.x86_64.rpm
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> <file>` where file is a log file
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 rpmlint.log"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
rpmlint.log
|
||||
"""
|
@@ -0,0 +1,59 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <project> <package> <repo> <arch>` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package> <repo> <arch> --multibuild-package=<flavor>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg standard x86_64 --multibuild-package=flavor1"
|
||||
# the option is allowed only in a package checkout
|
||||
Then the exit code is 2
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package>:<flavor> <repo> <arch>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg:flavor1 standard x86_64"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package>:<flavor> <repo> <arch> --source`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg:flavor1 standard x86_64 --source"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <package>:<flavor> <repo> <arch> --debuginfo`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory multibuild-pkg:flavor1 standard x86_64 --debuginfo"
|
||||
Then directory listing of "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-debuginfo-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
71
behave/features/getbinaries-project-repo-arch.feature
Normal file
71
behave/features/getbinaries-project-repo-arch.feature
Normal file
@@ -0,0 +1,71 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <project> <repo> <arch>` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <repo> <arch>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory standard x86_64"
|
||||
Then directory tree in "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <repo> <arch> --multibuild-package=<flavor>`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory standard x86_64 --multibuild-package=flavor1"
|
||||
# the option is allowed only in a package checkout
|
||||
Then the exit code is 2
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <project> <repo> <arch> --debuginfo`
|
||||
When I execute osc with args "getbinaries openSUSE:Factory standard x86_64 --debuginfo"
|
||||
Then directory tree in "{context.osc.temp}/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-debuginfo-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
44
behave/features/getbinaries-repo-arch-pkgcheckout.feature
Normal file
44
behave/features/getbinaries-repo-arch-pkgcheckout.feature
Normal file
@@ -0,0 +1,44 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <repo> <arch>` command from a package checkout
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "checkout openSUSE:Factory multibuild-pkg"
|
||||
And I set working directory to "{context.osc.temp}/openSUSE:Factory/multibuild-pkg"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch>` from a package checkout
|
||||
When I execute osc with args "getbinaries standard x86_64"
|
||||
Then directory listing of "{context.osc.temp}/openSUSE:Factory/multibuild-pkg/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch> --multibuild-package=<flavor>` from a package checkout
|
||||
When I execute osc with args "getbinaries standard x86_64 --multibuild-package=flavor1"
|
||||
Then directory listing of "{context.osc.temp}/openSUSE:Factory/multibuild-pkg/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch> --debuginfo` from a package checkout
|
||||
When I execute osc with args "getbinaries standard x86_64 --debuginfo"
|
||||
Then directory listing of "{context.osc.temp}/openSUSE:Factory/multibuild-pkg/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
105
behave/features/getbinaries-repo-arch-prjcheckout.feature
Normal file
105
behave/features/getbinaries-repo-arch-prjcheckout.feature
Normal file
@@ -0,0 +1,105 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <repo> <arch>` command from a project checkout
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "checkout openSUSE:Factory"
|
||||
And I set working directory to "{context.osc.temp}/openSUSE:Factory"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch>` from a project checkout
|
||||
When I execute osc with args "getbinaries standard x86_64"
|
||||
Then directory tree in "{context.osc.temp}/openSUSE:Factory/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch> --multibuild-package=<flavor>` from a project checkout
|
||||
When I execute osc with args "getbinaries standard x86_64 --multibuild-package=flavor1"
|
||||
# the option is allowed only in a package checkout
|
||||
Then the exit code is 2
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch> --sources` from a project checkout
|
||||
When I execute osc with args "getbinaries standard x86_64 --sources"
|
||||
Then directory tree in "{context.osc.temp}/openSUSE:Factory/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgA-3-1.1.src.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.src.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> <arch> --debuginfo` from a project checkout
|
||||
When I execute osc with args "getbinaries standard x86_64 --debuginfo"
|
||||
Then directory tree in "{context.osc.temp}/openSUSE:Factory/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-debuginfo-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
50
behave/features/getbinaries-repo-pkgcheckout.feature
Normal file
50
behave/features/getbinaries-repo-pkgcheckout.feature
Normal file
@@ -0,0 +1,50 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <repo>` command from a project checkout
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "checkout openSUSE:Factory multibuild-pkg"
|
||||
And I set working directory to "{context.osc.temp}/openSUSE:Factory/multibuild-pkg"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo>` from a package checkout
|
||||
Given I set working directory to "{context.osc.temp}/openSUSE:Factory/multibuild-pkg"
|
||||
When I execute osc with args "getbinaries standard"
|
||||
Then directory listing of "{context.osc.temp}/openSUSE:Factory/multibuild-pkg/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.i586.rpm
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> --multibuild-package=<flavor>` from a package checkout
|
||||
When I execute osc with args "getbinaries standard --multibuild-package=flavor1"
|
||||
Then directory listing of "{context.osc.temp}/openSUSE:Factory/multibuild-pkg/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-flavor1-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> --debuginfo` from a package checkout
|
||||
When I execute osc with args "getbinaries standard --debuginfo"
|
||||
Then directory listing of "{context.osc.temp}/openSUSE:Factory/multibuild-pkg/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.i586.rpm
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.i586.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.i586.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.x86_64.rpm
|
||||
_buildenv
|
||||
_statistics
|
||||
rpmlint.log
|
||||
"""
|
118
behave/features/getbinaries-repo-prjcheckout.feature
Normal file
118
behave/features/getbinaries-repo-prjcheckout.feature
Normal file
@@ -0,0 +1,118 @@
|
||||
@no-snapshot
|
||||
Feature: `osc getbinaries <repo>` command from a project checkout
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "checkout openSUSE:Factory"
|
||||
And I set working directory to "{context.osc.temp}/openSUSE:Factory"
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo>` from a project checkout
|
||||
When I execute osc with args "getbinaries standard"
|
||||
Then directory tree in "{context.osc.temp}/openSUSE:Factory/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.i586.rpm
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> --multibuild-package=<flavor>` from a project checkout
|
||||
When I execute osc with args "getbinaries standard --multibuild-package=flavor1"
|
||||
# the option is allowed only in a package checkout
|
||||
Then the exit code is 2
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> --sources` from a project checkout
|
||||
When I execute osc with args "getbinaries standard --sources"
|
||||
Then directory tree in "{context.osc.temp}/openSUSE:Factory/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.i586.rpm
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-1-1.1.src.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgA-3-1.1.src.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.src.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc getbinaries <repo> --debuginfo` from a project checkout
|
||||
When I execute osc with args "getbinaries standard --debuginfo"
|
||||
Then directory tree in "{context.osc.temp}/openSUSE:Factory/binaries/" is
|
||||
"""
|
||||
multibuild-pkg-1-1.1.i586.rpm
|
||||
multibuild-pkg-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.i586.rpm
|
||||
multibuild-pkg-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.i586.rpm
|
||||
multibuild-pkg-debugsource-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor1-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor1-debuginfo-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor1-debuginfo-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor2-1-1.1.x86_64.rpm
|
||||
multibuild-pkg-flavor2-debuginfo-1-1.1.i586.rpm
|
||||
multibuild-pkg-flavor2-debuginfo-1-1.1.x86_64.rpm
|
||||
test-pkgA-3-1.1.noarch.rpm
|
||||
test-pkgB-2-1.1.noarch.rpm
|
||||
multibuild-pkg/_buildenv
|
||||
multibuild-pkg/_statistics
|
||||
multibuild-pkg/rpmlint.log
|
||||
multibuild-pkg:flavor1/_buildenv
|
||||
multibuild-pkg:flavor1/_statistics
|
||||
multibuild-pkg:flavor1/rpmlint.log
|
||||
multibuild-pkg:flavor2/_buildenv
|
||||
multibuild-pkg:flavor2/_statistics
|
||||
multibuild-pkg:flavor2/rpmlint.log
|
||||
test-pkgA/_buildenv
|
||||
test-pkgA/_statistics
|
||||
test-pkgA/rpmlint.log
|
||||
test-pkgB/_buildenv
|
||||
test-pkgB/_statistics
|
||||
test-pkgB/rpmlint.log
|
||||
"""
|
33
behave/features/list.feature
Normal file
33
behave/features/list.feature
Normal file
@@ -0,0 +1,33 @@
|
||||
@no-snapshot
|
||||
Feature: `osc list` command
|
||||
|
||||
|
||||
Scenario: Run `osc list` with no arguments to display all projects
|
||||
When I execute osc with args "list"
|
||||
Then stdout is
|
||||
"""
|
||||
home:Admin
|
||||
openSUSE.org
|
||||
openSUSE:Factory
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc list` on a project to display project packages
|
||||
When I execute osc with args "list openSUSE:Factory"
|
||||
Then stdout is
|
||||
"""
|
||||
multibuild-pkg
|
||||
multibuild-pkg:flavor1
|
||||
multibuild-pkg:flavor2
|
||||
test-pkgA
|
||||
test-pkgB
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Run `osc list` on a project package to display package files
|
||||
When I execute osc with args "list openSUSE:Factory test-pkgA"
|
||||
Then stdout is
|
||||
"""
|
||||
test-pkgA.changes
|
||||
test-pkgA.spec
|
||||
"""
|
0
behave/features/steps/__init__.py
Normal file
0
behave/features/steps/__init__.py
Normal file
257
behave/features/steps/common.py
Normal file
257
behave/features/steps/common.py
Normal file
@@ -0,0 +1,257 @@
|
||||
import errno
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
import behave
|
||||
|
||||
|
||||
def makedirs(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
def run(cmd, shell=True, cwd=None, env=None):
|
||||
"""
|
||||
Run a command.
|
||||
Return exitcode, stdout, stderr
|
||||
"""
|
||||
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
shell=shell,
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
encoding="utf-8",
|
||||
universal_newlines=True,
|
||||
errors="surrogateescape",
|
||||
)
|
||||
|
||||
stdout, stderr = proc.communicate()
|
||||
return proc.returncode, stdout, stderr
|
||||
|
||||
|
||||
def check_exit_code(context):
|
||||
# check if the previous command finished successfully
|
||||
# or if the exit code was tested in a scenario
|
||||
if not getattr(context, "cmd", None):
|
||||
return
|
||||
|
||||
if context.cmd_exitcode_checked:
|
||||
return
|
||||
|
||||
the_exit_code_is(context, 0)
|
||||
|
||||
|
||||
def run_in_context(context, cmd, can_fail=False, **run_args):
|
||||
check_exit_code(context)
|
||||
|
||||
context.cmd = cmd
|
||||
|
||||
if hasattr(context.scenario, "working_dir") and 'cwd' not in run_args:
|
||||
run_args['cwd'] = context.scenario.working_dir
|
||||
|
||||
if hasattr(context.scenario, "PATH"):
|
||||
env = os.environ.copy()
|
||||
path = context.scenario.PATH
|
||||
env["PATH"] = path.replace("$PATH", env["PATH"])
|
||||
run_args["env"] = env
|
||||
|
||||
if context.config.userdata.get("DEBUG", False):
|
||||
print(f"DEBUG: command: {cmd}")
|
||||
|
||||
context.cmd_exitcode, context.cmd_stdout, context.cmd_stderr = run(cmd, **run_args)
|
||||
context.cmd_exitcode_checked = False
|
||||
|
||||
if context.config.userdata.get("DEBUG", False):
|
||||
print(f"DEBUG: exit code: {context.cmd_exitcode}")
|
||||
print(f"DEBUG: stdout: {context.cmd_stdout}")
|
||||
print(f"DEBUG: stderr: {context.cmd_stderr}")
|
||||
|
||||
if not can_fail and context.cmd_exitcode != 0:
|
||||
raise AssertionError('Running command "%s" failed: %s' % (cmd, context.cmd_exitcode))
|
||||
|
||||
|
||||
@behave.step("stdout contains \"{text}\"")
|
||||
def step_impl(context, text):
|
||||
if re.search(text.format(context=context), context.cmd_stdout):
|
||||
return
|
||||
raise AssertionError("Stdout doesn't contain: %s" % text)
|
||||
|
||||
|
||||
@behave.step("stderr contains \"{text}\"")
|
||||
def step_impl(context, text):
|
||||
if re.search(text.format(context=context), context.cmd_stderr):
|
||||
return
|
||||
raise AssertionError("Stderr doesn't contain: %s" % text)
|
||||
|
||||
|
||||
@behave.step("stdout is")
|
||||
def step_impl(context):
|
||||
expected = context.text.format(context=context).rstrip().split('\n')
|
||||
found = context.cmd_stdout.rstrip().split('\n')
|
||||
|
||||
if found == expected:
|
||||
return
|
||||
|
||||
expected_str = "\n".join(expected)
|
||||
found_str = "\n".join(found)
|
||||
raise AssertionError(f"Stdout is not:\n{expected_str}\n\nActual stdout:\n{found_str}")
|
||||
|
||||
|
||||
@behave.step('I set working directory to "{path}"')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
context.scenario.working_dir = path
|
||||
|
||||
|
||||
@behave.step('I set PATH to "{path}"')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
context.scenario.PATH = path
|
||||
|
||||
|
||||
@behave.step('I copy file "{source}" to "{destination}"')
|
||||
def step_impl(context, source, destination):
|
||||
# substitutions
|
||||
source = source.format(context=context)
|
||||
destination = destination.format(context=context)
|
||||
|
||||
# if destination is a directory, append the source filename
|
||||
if destination.endswith("/"):
|
||||
destination = os.path.join(destination, os.path.basename(source))
|
||||
|
||||
# copy file without attributes
|
||||
makedirs(os.path.dirname(destination))
|
||||
shutil.copyfile(source, destination)
|
||||
|
||||
|
||||
@behave.step('file "{path}" exists')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
if not os.path.isfile(path):
|
||||
raise AssertionError(f"File doesn't exist: {path}")
|
||||
|
||||
|
||||
@behave.step('file "{path}" does not exist')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
if os.path.isfile(path):
|
||||
raise AssertionError(f"File exists: {path}")
|
||||
|
||||
|
||||
@behave.step('file "{one}" is identical to "{two}"')
|
||||
def step_impl(context, one, two):
|
||||
one = one.format(context=context)
|
||||
two = two.format(context=context)
|
||||
data_one = open(one, "r").read()
|
||||
data_two = open(two, "r").read()
|
||||
if data_one != data_two:
|
||||
raise AssertionError(f"Files differ: {one} != {two}")
|
||||
|
||||
|
||||
@behave.step('directory "{path}" exists')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
if not os.path.isdir(path):
|
||||
raise AssertionError(f"Directory doesn't exist: {path}")
|
||||
|
||||
|
||||
@behave.step('directory "{path}" does not exist')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
if os.path.isdir(path):
|
||||
raise AssertionError(f"Directory exists: {path}")
|
||||
|
||||
|
||||
@behave.step('I create file "{path}" with perms "{mode}"')
|
||||
def step_impl(context, path, mode):
|
||||
path = path.format(context=context)
|
||||
mode = int(mode, 8)
|
||||
content = context.text.format(context=context).rstrip()
|
||||
|
||||
makedirs(os.path.dirname(path))
|
||||
open(path, "w").write(content)
|
||||
os.chmod(path, mode)
|
||||
|
||||
|
||||
@behave.step("the exit code is {exitcode}")
|
||||
def the_exit_code_is(context, exitcode):
|
||||
if context.cmd_exitcode != int(exitcode):
|
||||
raise AssertionError(f"Command has exited with code {context.cmd_exitcode}: {context.cmd}")
|
||||
context.cmd_exitcode_checked = True
|
||||
|
||||
|
||||
@behave.step('directory listing of "{path}" is')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
expected = context.text.format(context=context).rstrip().split('\n')
|
||||
expected = [i for i in expected if i.strip()]
|
||||
found = os.listdir(path)
|
||||
|
||||
expected = set(expected)
|
||||
found = set(found)
|
||||
|
||||
if found == expected:
|
||||
return
|
||||
|
||||
extra = sorted(set(found) - set(expected))
|
||||
missing = sorted(set(expected) - set(found))
|
||||
|
||||
msg = []
|
||||
if extra:
|
||||
msg.append("Unexpected files found on disk:")
|
||||
for fn in extra:
|
||||
msg.append(f" {fn}")
|
||||
if missing:
|
||||
msg.append("Files missing on disk:")
|
||||
for fn in missing:
|
||||
msg.append(f" {fn}")
|
||||
|
||||
msg = "\n".join(msg)
|
||||
|
||||
raise AssertionError(f"Directory listing does not match:\n{msg}")
|
||||
|
||||
|
||||
@behave.step('directory tree in "{path}" is')
|
||||
def step_impl(context, path):
|
||||
path = path.format(context=context)
|
||||
path = os.path.abspath(path)
|
||||
expected = context.text.format(context=context).rstrip().split('\n')
|
||||
expected = [i for i in expected if i.strip()]
|
||||
|
||||
found = []
|
||||
for root, dirs, files in os.walk(path):
|
||||
for fn in files:
|
||||
file_abspath = os.path.join(root, fn)
|
||||
file_relpath = file_abspath[len(path) + 1:]
|
||||
found.append(file_relpath)
|
||||
# found = os.listdir(path)
|
||||
|
||||
expected = set(expected)
|
||||
found = set(found)
|
||||
|
||||
if found == expected:
|
||||
return
|
||||
|
||||
extra = sorted(set(found) - set(expected))
|
||||
missing = sorted(set(expected) - set(found))
|
||||
|
||||
msg = []
|
||||
if extra:
|
||||
msg.append("Unexpected files found on disk:")
|
||||
for fn in extra:
|
||||
msg.append(f" {fn}")
|
||||
if missing:
|
||||
msg.append("Files missing on disk:")
|
||||
for fn in missing:
|
||||
msg.append(f" {fn}")
|
||||
|
||||
msg = "\n".join(msg)
|
||||
|
||||
raise AssertionError(f"Directory listing does not match:\n{msg}")
|
76
behave/features/steps/kanku.py
Normal file
76
behave/features/steps/kanku.py
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
import behave
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
|
||||
class Kanku:
|
||||
def __init__(self, context, kankufile):
|
||||
self.kankufile = kankufile
|
||||
self.kankudir = os.path.dirname(self.kankufile)
|
||||
self.domain_name = self._get_domain_name()
|
||||
self.ip = self._get_ip()
|
||||
|
||||
def _get_domain_name(self):
|
||||
"""
|
||||
Get domain name directly from KankuFile yaml
|
||||
"""
|
||||
yaml = YAML(typ='safe')
|
||||
doc = yaml.load(open(self.kankufile, "r"))
|
||||
return doc["domain_name"]
|
||||
|
||||
def _run_kanku(self, args):
|
||||
cmd = ["kanku"] + args
|
||||
env = os.environ.copy()
|
||||
env["KANKU_CONFIG"] = self.kankufile
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
cwd=self.kankudir,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
encoding="utf-8"
|
||||
)
|
||||
return proc
|
||||
|
||||
def _get_ip(self):
|
||||
"""
|
||||
Get IP from calling `kanku ip`
|
||||
"""
|
||||
proc = self._run_kanku(["ip"])
|
||||
stdout, stderr = proc.communicate()
|
||||
match = re.search(r"IP Address: ([\d\.]+)", stderr)
|
||||
return match.group(1)
|
||||
|
||||
def create_snapshot(self):
|
||||
# unmount /tmp/kanku so we are able to create a snapshot of the VM
|
||||
self.run_command("umount /tmp/kanku")
|
||||
proc = self._run_kanku(["snapshot", "--create", "--name", "current"])
|
||||
proc.communicate()
|
||||
|
||||
def revert_to_snapshot(self):
|
||||
proc = self._run_kanku(["snapshot", "--revert", "--name", "current"])
|
||||
proc.communicate()
|
||||
|
||||
def delete_snapshot(self):
|
||||
proc = self._run_kanku(["snapshot", "--remove", "--name", "current"])
|
||||
proc.communicate()
|
||||
|
||||
def run_command(self, ssh_cmd, user="root"):
|
||||
proc = self._run_kanku(["ssh", "-u", user, "--execute", ssh_cmd])
|
||||
proc.wait()
|
||||
|
||||
|
||||
@behave.step("I create VM snapshot")
|
||||
def func(context, args):
|
||||
context.kanku.create_snapshot(sudo=True)
|
||||
|
||||
|
||||
@behave.step("I revert to VM snapshot")
|
||||
def func(context, args):
|
||||
context.kanku.revert_to_snapshot(sudo=True)
|
75
behave/features/steps/osc.py
Normal file
75
behave/features/steps/osc.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
import behave
|
||||
|
||||
from steps.common import run_in_context
|
||||
|
||||
|
||||
class Osc:
|
||||
def __init__(self, context):
|
||||
self.temp = tempfile.mkdtemp(prefix="osc_behave_")
|
||||
|
||||
if not hasattr(context, "kanku"):
|
||||
raise RuntimeError("context doesn't have kanku object set")
|
||||
|
||||
self.oscrc = os.path.join(self.temp, "oscrc")
|
||||
with open(self.oscrc, "w") as f:
|
||||
f.write("[general]\n")
|
||||
f.write("\n")
|
||||
f.write(f"[https://{context.kanku.ip}]\n")
|
||||
f.write("user=Admin\n")
|
||||
f.write("pass=opensuse\n")
|
||||
f.write("credentials_mgr_class=osc.credentials.PlaintextConfigFileCredentialsManager\n")
|
||||
f.write("sslcertck=0\n")
|
||||
f.write("trusted_prj=openSUSE.org:openSUSE:Tumbleweed\n")
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
shutil.rmtree(self.temp)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def get_cmd(self, context):
|
||||
osc_cmd = context.config.userdata.get("osc", "osc")
|
||||
cmd = [osc_cmd]
|
||||
cmd += ["--config", self.oscrc]
|
||||
cmd += ["-A", f"https://{context.kanku.ip}"]
|
||||
return cmd
|
||||
|
||||
|
||||
@behave.step("I execute osc with args \"{args}\"")
|
||||
def step_impl(context, args):
|
||||
args = args.format(context=context)
|
||||
cmd = context.osc.get_cmd(context) + [args]
|
||||
cmd = " ".join(cmd)
|
||||
run_in_context(context, cmd, can_fail=True)
|
||||
|
||||
|
||||
@behave.step('I wait for osc results for "{project}" "{package}"')
|
||||
def step_impl(context, project, package):
|
||||
args = f"results {project} {package} --csv --format='%(code)s,%(dirty)s'"
|
||||
cmd = context.osc.get_cmd(context) + [args]
|
||||
cmd = " ".join(cmd)
|
||||
|
||||
while True:
|
||||
# wait for a moment before checking the status even for the first time
|
||||
# for some reason, packages appear to be "broken" for a while after they get commited
|
||||
time.sleep(5)
|
||||
|
||||
run_in_context(context, cmd, can_fail=True)
|
||||
results = []
|
||||
for line in context.cmd_stdout.splitlines():
|
||||
code, dirty = line.split(",")
|
||||
dirty = dirty.lower() == "true"
|
||||
results.append((code, dirty))
|
||||
|
||||
if all((code == "succeeded" and not dirty for code, dirty in results)):
|
||||
# all builds have succeeded and all dirty flags are false
|
||||
break
|
||||
|
||||
if any((code in ("unresolvable", "failed", "broken", "blocked", "locked", "excluded") and not dirty for code, dirty in results)):
|
||||
# failed build with dirty flag false
|
||||
raise AssertionError("Package build failed:\n" + context.cmd_stdout)
|
Reference in New Issue
Block a user