Skip to content

Commit

Permalink
Merge pull request #8308 from jwhonce/jira/run-976
Browse files Browse the repository at this point in the history
Refactor to use DockerClient vs APIClient
  • Loading branch information
openshift-merge-robot authored Nov 13, 2020
2 parents 0b3f789 + a1187ee commit 0b1a60e
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 218 deletions.
18 changes: 9 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

# -- Project information -----------------------------------------------------

project = 'Podman'
copyright = '2019, team'
author = 'team'
project = "Podman"
copyright = "2019, team"
author = "team"


# -- General configuration ---------------------------------------------------
Expand All @@ -28,33 +28,33 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'recommonmark',
"recommonmark",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

master_doc = 'index'
master_doc = "index"

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

html_css_files = [
'custom.css',
"custom.css",
]

# -- Extension configuration -------------------------------------------------
36 changes: 15 additions & 21 deletions pkg/api/handlers/compat/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ func InspectNetwork(w http.ResponseWriter, r *http.Request) {

// FYI scope and version are currently unused but are described by the API
// Leaving this for if/when we have to enable these
//query := struct {
// query := struct {
// scope string
// verbose bool
//}{
// }{
// // override any golang type defaults
//}
//decoder := r.Context().Value("decoder").(*schema.Decoder)
//if err := decoder.Decode(&query, r.URL.Query()); err != nil {
// }
// decoder := r.Context().Value("decoder").(*schema.Decoder)
// if err := decoder.Decode(&query, r.URL.Query()); err != nil {
// utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
// return
//}
// }
config, err := runtime.GetConfig()
if err != nil {
utils.InternalServerError(w, err)
Expand Down Expand Up @@ -119,7 +119,7 @@ func getNetworkResourceByName(name string, runtime *libpod.Runtime) (*types.Netw
}
report := types.NetworkResource{
Name: name,
ID: "",
ID: name,
Created: time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec)), // nolint: unconvert
Scope: "",
Driver: network.DefaultNetworkDriver,
Expand Down Expand Up @@ -207,6 +207,7 @@ func ListNetworks(w http.ResponseWriter, r *http.Request) {
}

reports := make([]*types.NetworkResource, 0, len(netNames))
logrus.Errorf("netNames: %q", strings.Join(netNames, ", "))
for _, name := range netNames {
report, err := getNetworkResourceByName(name, runtime)
if err != nil {
Expand Down Expand Up @@ -276,21 +277,14 @@ func CreateNetwork(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, err)
return
}
report := types.NetworkCreate{
CheckDuplicate: networkCreate.CheckDuplicate,
Driver: networkCreate.Driver,
Scope: networkCreate.Scope,
EnableIPv6: networkCreate.EnableIPv6,
IPAM: networkCreate.IPAM,
Internal: networkCreate.Internal,
Attachable: networkCreate.Attachable,
Ingress: networkCreate.Ingress,
ConfigOnly: networkCreate.ConfigOnly,
ConfigFrom: networkCreate.ConfigFrom,
Options: networkCreate.Options,
Labels: networkCreate.Labels,

body := struct {
Id string
Warning []string
}{
Id: name,
}
utils.WriteResponse(w, http.StatusOK, report)
utils.WriteResponse(w, http.StatusCreated, body)
}

func RemoveNetwork(w http.ResponseWriter, r *http.Request) {
Expand Down
33 changes: 28 additions & 5 deletions test/apiv2/rest_api/test_rest_v2_0_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,34 @@ def test_logs_containers(self):
r = requests.get(_url(ctnr("/containers/{}/logs?stdout=true")))
self.assertEqual(r.status_code, 200, r.text)

def test_post_create(self):
self.skipTest("TODO: create request body")
r = requests.post(_url("/containers/create?args=True"))
self.assertEqual(r.status_code, 200, r.text)
json.loads(r.text)
def test_post_create_compat(self):
"""Create network and container then connect to network"""
net = requests.post(
PODMAN_URL + "/v1.40/networks/create", json={"Name": "TestNetwork"}
)
self.assertEqual(net.status_code, 201, net.text)

create = requests.post(
PODMAN_URL + "/v1.40/containers/create?name=postCreate",
json={
"Cmd": ["date"],
"Image": "alpine:latest",
"NetworkDisabled": False,
"NetworkConfig": {
"EndpointConfig": {"TestNetwork": {"Aliases": ["test_post_create"]}}
},
},
)
self.assertEqual(create.status_code, 201, create.text)
payload = json.loads(create.text)
self.assertIsNotNone(payload["Id"])

connect = requests.post(
PODMAN_URL + "/v1.40/networks/TestNetwork/connect",
json={"Container": payload["Id"]},
)
self.assertEqual(connect.status_code, 200, create.text)
self.assertEqual(connect.text, "OK\n")

def test_commit(self):
r = requests.post(_url(ctnr("/commit?container={}")))
Expand Down
17 changes: 9 additions & 8 deletions test/python/docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import subprocess
import tempfile

from docker import DockerClient

from test.python.docker import constant


Expand Down Expand Up @@ -141,16 +143,15 @@ def run(self, command, *args, **kwargs):
def tear_down(self):
shutil.rmtree(self.anchor_directory, ignore_errors=True)

def restore_image_from_cache(self, client):
img = os.path.join(self.image_cache, constant.ALPINE_TARBALL)
if not os.path.exists(img):
client.pull(constant.ALPINE)
image = client.get_image(constant.ALPINE)
with open(img, mode="wb") as tarball:
for frame in image:
def restore_image_from_cache(self, client: DockerClient):
path = os.path.join(self.image_cache, constant.ALPINE_TARBALL)
if not os.path.exists(path):
img = client.images.pull(constant.ALPINE)
with open(path, mode="wb") as tarball:
for frame in img.save(named=True):
tarball.write(frame)
else:
self.run("load", "-i", img, check=True)
self.run("load", "-i", path, check=True)

def flush_image_cache(self):
for f in pathlib.Path(self.image_cache).glob("*.tar"):
Expand Down
24 changes: 13 additions & 11 deletions test/python/docker/common.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from docker import APIClient
from docker import DockerClient

from test.python.docker import constant


def run_top_container(client: APIClient):
c = client.create_container(
def run_top_container(client: DockerClient):
c = client.containers.create(
constant.ALPINE, command="top", detach=True, tty=True, name="top"
)
client.start(c.get("Id"))
return c.get("Id")
c.start()
return c.id


def remove_all_containers(client: APIClient):
for ctnr in client.containers(quiet=True):
client.remove_container(ctnr, force=True)
def remove_all_containers(client: DockerClient):
for ctnr in client.containers.list(all=True):
ctnr.remove(force=True)


def remove_all_images(client: APIClient):
for image in client.images(quiet=True):
client.remove_image(image, force=True)
def remove_all_images(client: DockerClient):
for img in client.images.list():
# FIXME should DELETE /images accept the sha256: prefix?
id_ = img.id.removeprefix("sha256:")
client.images.remove(id_, force=True)
Loading

0 comments on commit 0b1a60e

Please sign in to comment.