Skip to content

Commit 9a40318

Browse files
authored
Allow using readonly/partitioned clients (#185)
1 parent c70a5cb commit 9a40318

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ steps:
9191
stream_switching: true
9292
```
9393

94+
### Use readonly/partitioned clients
95+
96+
Readonly and partitioned client workspaces can be used to reduce impact of automated build systems on Perforce server performance.
97+
See related article [Readonly and Partitioned Client Workspaces](https://community.perforce.com/s/article/15372).
98+
99+
Note that existing client workspaces must be deleted and re-created to change type.
100+
101+
```yaml
102+
steps:
103+
plugins:
104+
- improbable-eng/perforce:
105+
client_type: partitioned
106+
```
107+
94108
## Triggering Builds
95109

96110
There are a few options for triggering builds that use this plugin, in this order from least valuable but most convenient to most valuable but least convenient.

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ configuration:
2121
type: string
2222
client_options:
2323
type: string
24+
client_type:
25+
type: string
2426
backup_changelists:
2527
type: bool

python/buildkite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def get_config():
5151
conf['sync'] = list_from_env_array('BUILDKITE_PLUGIN_PERFORCE_SYNC')
5252
conf['parallel'] = os.environ.get('BUILDKITE_PLUGIN_PERFORCE_PARALLEL') or 0
5353
conf['client_options'] = os.environ.get('BUILDKITE_PLUGIN_PERFORCE_CLIENT_OPTIONS')
54+
conf['client_type'] = os.environ.get('BUILDKITE_PLUGIN_PERFORCE_CLIENT_TYPE')
5455

5556
if 'BUILDKITE_PLUGIN_PERFORCE_ROOT' in os.environ and not __LOCAL_RUN__:
5657
raise Exception("Custom P4 root is for use in unit tests only")

python/fixture/server.zip

395 Bytes
Binary file not shown.

python/perforce.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
class P4Repo:
1717
"""A class for manipulating perforce workspaces"""
18-
def __init__(self, root=None, view=None, stream=None,
19-
sync=None, client_options=None, parallel=0):
18+
def __init__(self, root=None, view=None, stream=None, sync=None,
19+
client_options=None, client_type=None, parallel=0):
2020
"""
2121
root: Directory in which to create the client workspace
2222
view: Client workspace mapping
2323
stream: Client workspace stream. Overrides view parameter.
2424
sync: List of paths to sync. Defaults to entire view.
2525
client_options: Additional options to add to client. (e.g. allwrite)
26+
client_type: Type of client (writeable, readonly, partitioned)
2627
parallel: How many threads to use for parallel sync.
2728
"""
2829
self.root = os.path.abspath(root or '')
@@ -31,6 +32,7 @@ def __init__(self, root=None, view=None, stream=None,
3132
self.sync_paths = sync or ['//...']
3233
assert isinstance(self.sync_paths, list)
3334
self.client_options = client_options or ''
35+
self.client_type = client_type or 'writeable'
3436
self.parallel = parallel
3537

3638
self.created_client = False
@@ -90,6 +92,7 @@ def _setup_client(self):
9092
client._stream = self.stream
9193
if self.view:
9294
client._view = self.view
95+
client._type = self.client_type
9396

9497
# unless overidden, overwrite writeable-but-unopened files
9598
# (e.g. interrupted syncs, artefacts that have been checked-in)

python/test_perforce.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ def test_checkout_label(server, tmpdir):
256256
with open(os.path.join(tmpdir, "file.txt")) as content:
257257
assert content.read() == "Hello World\n", "Unexpected content in workspace file"
258258

259+
def test_readonly_client(server, tmpdir):
260+
"""Test creation of a readonly client"""
261+
repo = P4Repo(root=tmpdir, client_type='readonly')
262+
repo.sync()
263+
assert "file.txt" in os.listdir(tmpdir), "Workspace file was not synced"
264+
265+
def test_partitioned_client(server, tmpdir):
266+
"""Test creation of a partitioned client"""
267+
repo = P4Repo(root=tmpdir, client_type='partitioned')
268+
repo.sync()
269+
assert "file.txt" in os.listdir(tmpdir), "Workspace file was not synced"
270+
271+
def test_modify_client_type(server, tmpdir):
272+
"""Test modifying a clients type"""
273+
repo = P4Repo(root=tmpdir, client_type='writeable')
274+
repo.sync()
275+
276+
with pytest.raises(Exception, match=r'Client storage type cannot be changed after client is created'):
277+
repo = P4Repo(root=tmpdir, client_type='readonly')
278+
repo.sync()
279+
259280
def test_workspace_recovery(server, tmpdir):
260281
"""Test that we can detect and recover from various workspace snafus"""
261282
repo = P4Repo(root=tmpdir)

0 commit comments

Comments
 (0)